Conform more of the codebase to strictNullChecks + noImplicitAny (#11179)
This commit is contained in:
parent
7c211b0587
commit
a294ba2ad4
17 changed files with 104 additions and 88 deletions
|
@ -25,20 +25,19 @@ import {
|
|||
} from "matrix-js-sdk/src/interactive-auth";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
||||
|
||||
import getEntryComponentForLoginType, { IStageComponent } from "../views/auth/InteractiveAuthEntryComponents";
|
||||
import Spinner from "../views/elements/Spinner";
|
||||
|
||||
export const ERROR_USER_CANCELLED = new Error("User cancelled auth session");
|
||||
|
||||
type InteractiveAuthCallbackSuccess = (
|
||||
type InteractiveAuthCallbackSuccess<T> = (
|
||||
success: true,
|
||||
response?: IAuthData,
|
||||
response: T,
|
||||
extra?: { emailSid?: string; clientSecret?: string },
|
||||
) => void;
|
||||
type InteractiveAuthCallbackFailure = (success: false, response: IAuthData | Error) => void;
|
||||
export type InteractiveAuthCallback = InteractiveAuthCallbackSuccess & InteractiveAuthCallbackFailure;
|
||||
export type InteractiveAuthCallback<T> = InteractiveAuthCallbackSuccess<T> & InteractiveAuthCallbackFailure;
|
||||
|
||||
export interface InteractiveAuthProps<T> {
|
||||
// matrix client to use for UI auth requests
|
||||
|
@ -62,7 +61,7 @@ export interface InteractiveAuthProps<T> {
|
|||
continueText?: string;
|
||||
continueKind?: string;
|
||||
// callback
|
||||
makeRequest(auth: IAuthDict | null): Promise<UIAResponse<T>>;
|
||||
makeRequest(auth: IAuthDict | null): Promise<T>;
|
||||
// callback called when the auth process has finished,
|
||||
// successfully or unsuccessfully.
|
||||
// @param {boolean} status True if the operation requiring
|
||||
|
@ -75,7 +74,7 @@ export interface InteractiveAuthProps<T> {
|
|||
// the auth session.
|
||||
// * clientSecret {string} The client secret used in auth
|
||||
// sessions with the ID server.
|
||||
onAuthFinished: InteractiveAuthCallback;
|
||||
onAuthFinished: InteractiveAuthCallback<T>;
|
||||
// As js-sdk interactive-auth
|
||||
requestEmailToken?(email: string, secret: string, attempt: number, session: string): Promise<{ sid: string }>;
|
||||
// Called when the stage changes, or the stage's phase changes. First
|
||||
|
@ -94,7 +93,7 @@ interface IState {
|
|||
}
|
||||
|
||||
export default class InteractiveAuthComponent<T> extends React.Component<InteractiveAuthProps<T>, IState> {
|
||||
private readonly authLogic: InteractiveAuth;
|
||||
private readonly authLogic: InteractiveAuth<T>;
|
||||
private readonly intervalId: number | null = null;
|
||||
private readonly stageComponent = createRef<IStageComponent>();
|
||||
|
||||
|
@ -108,7 +107,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
|
|||
submitButtonEnabled: false,
|
||||
};
|
||||
|
||||
this.authLogic = new InteractiveAuth({
|
||||
this.authLogic = new InteractiveAuth<T>({
|
||||
authData: this.props.authData,
|
||||
doRequest: this.requestCallback,
|
||||
busyChanged: this.onBusyChanged,
|
||||
|
@ -211,7 +210,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
|
|||
);
|
||||
};
|
||||
|
||||
private requestCallback = (auth: IAuthDict | null, background: boolean): Promise<UIAResponse<T>> => {
|
||||
private requestCallback = (auth: IAuthDict | null, background: boolean): Promise<T> => {
|
||||
// This wrapper just exists because the js-sdk passes a second
|
||||
// 'busy' param for backwards compat. This throws the tests off
|
||||
// so discard it here.
|
||||
|
|
|
@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { AuthType, createClient, IAuthDict, IAuthData, IInputs, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import { AuthType, createClient, IAuthData, IAuthDict, IInputs, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import React, { Fragment, ReactNode } from "react";
|
||||
import { IRegisterRequestParams, IRequestTokenResponse, MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import classNames from "classnames";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ISSOFlow, SSOAction } from "matrix-js-sdk/src/@types/auth";
|
||||
import { RegisterResponse } from "matrix-js-sdk/src/@types/registration";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import { adminContactStrings, messageForResourceLimitError, resourceLimitStrings } from "../../../utils/ErrorUtils";
|
||||
|
@ -305,7 +306,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
);
|
||||
};
|
||||
|
||||
private onUIAuthFinished: InteractiveAuthCallback = async (success, response): Promise<void> => {
|
||||
private onUIAuthFinished: InteractiveAuthCallback<RegisterResponse> = async (success, response): Promise<void> => {
|
||||
if (!this.state.matrixClient) throw new Error("Matrix client has not yet been loaded");
|
||||
|
||||
debuglog("Registration: ui authentication finished: ", { success, response });
|
||||
|
@ -329,8 +330,8 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
<p>{errorDetail}</p>
|
||||
</div>
|
||||
);
|
||||
} else if ((response as IAuthData).required_stages?.includes(AuthType.Msisdn)) {
|
||||
const flows = (response as IAuthData).available_flows ?? [];
|
||||
} else if ((response as IAuthData).flows?.some((flow) => flow.stages.includes(AuthType.Msisdn))) {
|
||||
const flows = (response as IAuthData).flows ?? [];
|
||||
const msisdnAvailable = flows.some((flow) => flow.stages.includes(AuthType.Msisdn));
|
||||
if (!msisdnAvailable) {
|
||||
errorText = _t("This server does not support authentication with a phone number.");
|
||||
|
@ -349,15 +350,15 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
return;
|
||||
}
|
||||
|
||||
const userId = (response as IAuthData).user_id;
|
||||
const accessToken = (response as IAuthData).access_token;
|
||||
const userId = (response as RegisterResponse).user_id;
|
||||
const accessToken = (response as RegisterResponse).access_token;
|
||||
if (!userId || !accessToken) throw new Error("Registration failed");
|
||||
|
||||
MatrixClientPeg.setJustRegisteredUserId(userId);
|
||||
|
||||
const newState: Partial<IState> = {
|
||||
doingUIAuth: false,
|
||||
registeredUsername: (response as IAuthData).user_id,
|
||||
registeredUsername: userId,
|
||||
differentLoggedInUserId: undefined,
|
||||
completedNoSignin: false,
|
||||
// we're still busy until we get unmounted: don't show the registration form again
|
||||
|
@ -370,10 +371,8 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// starting the registration process. This isn't perfect since it's possible
|
||||
// the user had a separate guest session they didn't actually mean to replace.
|
||||
const [sessionOwner, sessionIsGuest] = await Lifecycle.getStoredSessionOwner();
|
||||
if (sessionOwner && !sessionIsGuest && sessionOwner !== (response as IAuthData).user_id) {
|
||||
logger.log(
|
||||
`Found a session for ${sessionOwner} but ${(response as IAuthData).user_id} has just registered.`,
|
||||
);
|
||||
if (sessionOwner && !sessionIsGuest && sessionOwner !== userId) {
|
||||
logger.log(`Found a session for ${sessionOwner} but ${userId} has just registered.`);
|
||||
newState.differentLoggedInUserId = sessionOwner;
|
||||
}
|
||||
|
||||
|
@ -390,7 +389,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// as the client that started registration may be gone by the time we've verified the email, and only the client
|
||||
// that verified the email is guaranteed to exist, we'll always do the login in that client.
|
||||
const hasEmail = Boolean(this.state.formVals.email);
|
||||
const hasAccessToken = Boolean((response as IAuthData).access_token);
|
||||
const hasAccessToken = Boolean(accessToken);
|
||||
debuglog("Registration: ui auth finished:", { hasEmail, hasAccessToken });
|
||||
// don’t log in if we found a session for a different user
|
||||
if (!hasEmail && hasAccessToken && !newState.differentLoggedInUserId) {
|
||||
|
@ -399,7 +398,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
await this.props.onLoggedIn(
|
||||
{
|
||||
userId,
|
||||
deviceId: (response as IAuthData).device_id,
|
||||
deviceId: (response as RegisterResponse).device_id!,
|
||||
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
|
||||
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
|
||||
accessToken,
|
||||
|
@ -461,7 +460,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
});
|
||||
};
|
||||
|
||||
private makeRegisterRequest = (auth: IAuthDict | null): Promise<IAuthData> => {
|
||||
private makeRegisterRequest = (auth: IAuthDict | null): Promise<RegisterResponse> => {
|
||||
if (!this.state.matrixClient) throw new Error("Matrix client has not yet been loaded");
|
||||
|
||||
const registerParams: IRegisterRequestParams = {
|
||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { AuthType, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { _t } from "../../../languageHandler";
|
||||
|
@ -109,7 +110,10 @@ export default class DeactivateAccountDialog extends React.Component<IProps, ISt
|
|||
this.setState({ bodyText, continueText, continueKind });
|
||||
};
|
||||
|
||||
private onUIAuthFinished: InteractiveAuthCallback = (success, result) => {
|
||||
private onUIAuthFinished: InteractiveAuthCallback<Awaited<ReturnType<MatrixClient["deactivateAccount"]>>> = (
|
||||
success,
|
||||
result,
|
||||
) => {
|
||||
if (success) return; // great! makeRequest() will be called too.
|
||||
|
||||
if (result === ERROR_USER_CANCELLED) {
|
||||
|
|
|
@ -18,7 +18,8 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { AuthType, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
||||
import { AuthType } from "matrix-js-sdk/src/interactive-auth";
|
||||
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import AccessibleButton from "../elements/AccessibleButton";
|
||||
|
@ -70,7 +71,7 @@ export interface InteractiveAuthDialogProps<T = unknown>
|
|||
// Default is defined in _getDefaultDialogAesthetics()
|
||||
aestheticsForStagePhases?: DialogAesthetics;
|
||||
|
||||
onFinished(success?: boolean, result?: IAuthData | Error | null): void;
|
||||
onFinished(success?: boolean, result?: UIAResponse<T> | Error | null): void;
|
||||
}
|
||||
|
||||
interface IState {
|
||||
|
@ -116,7 +117,7 @@ export default class InteractiveAuthDialog<T> extends React.Component<Interactiv
|
|||
};
|
||||
}
|
||||
|
||||
private onAuthFinished: InteractiveAuthCallback = (success, result): void => {
|
||||
private onAuthFinished: InteractiveAuthCallback<T> = (success, result): void => {
|
||||
if (success) {
|
||||
this.props.onFinished(true, result);
|
||||
} else {
|
||||
|
|
|
@ -760,7 +760,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
|
|||
const lookup = await MatrixClientPeg.safeGet().lookupThreePid("email", term, token);
|
||||
if (term !== this.state.filterText) return; // abandon hope
|
||||
|
||||
if (!lookup || !lookup.mxid) {
|
||||
if (!lookup || !("mxid" in lookup)) {
|
||||
// We weren't able to find anyone - we're already suggesting the plain email
|
||||
// as an alternative, so do nothing.
|
||||
return;
|
||||
|
|
|
@ -25,7 +25,7 @@ import { RoomPreviewOpts, RoomViewLifecycle } from "@matrix-org/react-sdk-module
|
|||
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
import { _t } from "../../../languageHandler";
|
||||
import { _t, UserFriendlyError } from "../../../languageHandler";
|
||||
import SdkConfig from "../../../SdkConfig";
|
||||
import IdentityAuthClient from "../../../IdentityAuthClient";
|
||||
import InviteReason from "../elements/InviteReason";
|
||||
|
@ -153,6 +153,9 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
|
|||
this.props.invitedEmail,
|
||||
identityAccessToken!,
|
||||
);
|
||||
if (!("mxid" in result)) {
|
||||
throw new UserFriendlyError("Unable to find user by email");
|
||||
}
|
||||
this.setState({ invitedEmailMxid: result.mxid });
|
||||
} catch (err) {
|
||||
this.setState({ threePidFetchError: err as MatrixError });
|
||||
|
|
|
@ -32,7 +32,7 @@ const makeDeleteRequest =
|
|||
export const deleteDevicesWithInteractiveAuth = async (
|
||||
matrixClient: MatrixClient,
|
||||
deviceIds: string[],
|
||||
onFinished: InteractiveAuthCallback,
|
||||
onFinished: InteractiveAuthCallback<void>,
|
||||
): Promise<void> => {
|
||||
if (!deviceIds.length) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue