Apply strictNullChecks
to src/components/views/auth/*
(#10299
* Apply `strictNullChecks` to src/components/views/auth/* * Iterate PR
This commit is contained in:
parent
c79eff2292
commit
32aa18ff2e
16 changed files with 127 additions and 122 deletions
|
@ -83,7 +83,7 @@ export const DEFAULT_PHASE = 0;
|
|||
interface IAuthEntryProps {
|
||||
matrixClient: MatrixClient;
|
||||
loginType: string;
|
||||
authSessionId: string;
|
||||
authSessionId?: string;
|
||||
errorText?: string;
|
||||
errorCode?: string;
|
||||
// Is the auth logic currently waiting for something to happen?
|
||||
|
@ -120,7 +120,7 @@ export class PasswordAuthEntry extends React.Component<IAuthEntryProps, IPasswor
|
|||
type: AuthType.Password,
|
||||
// TODO: Remove `user` once servers support proper UIA
|
||||
// See https://github.com/vector-im/element-web/issues/10312
|
||||
user: this.props.matrixClient.credentials.userId,
|
||||
user: this.props.matrixClient.credentials.userId ?? undefined,
|
||||
identifier: {
|
||||
type: "m.id.user",
|
||||
user: this.props.matrixClient.credentials.userId,
|
||||
|
@ -286,7 +286,7 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
// }
|
||||
// }
|
||||
|
||||
const allPolicies = this.props.stageParams.policies || {};
|
||||
const allPolicies = this.props.stageParams?.policies || {};
|
||||
const prefLang = SettingsStore.getValue("language");
|
||||
const initToggles: Record<string, boolean> = {};
|
||||
const pickedPolicies: {
|
||||
|
@ -300,12 +300,12 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
// Pick a language based on the user's language, falling back to english,
|
||||
// and finally to the first language available. If there's still no policy
|
||||
// available then the homeserver isn't respecting the spec.
|
||||
let langPolicy = policy[prefLang];
|
||||
let langPolicy: LocalisedPolicy | undefined = policy[prefLang];
|
||||
if (!langPolicy) langPolicy = policy["en"];
|
||||
if (!langPolicy) {
|
||||
// last resort
|
||||
const firstLang = Object.keys(policy).find((e) => e !== "version");
|
||||
langPolicy = policy[firstLang];
|
||||
langPolicy = firstLang ? policy[firstLang] : undefined;
|
||||
}
|
||||
if (!langPolicy) throw new Error("Failed to find a policy to show the user");
|
||||
|
||||
|
@ -358,7 +358,7 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
return <Spinner />;
|
||||
}
|
||||
|
||||
const checkboxes = [];
|
||||
const checkboxes: JSX.Element[] = [];
|
||||
let allChecked = true;
|
||||
for (const policy of this.state.policies) {
|
||||
const checked = this.state.toggledPolicies[policy.id];
|
||||
|
@ -384,7 +384,7 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
);
|
||||
}
|
||||
|
||||
let submitButton;
|
||||
let submitButton: JSX.Element | undefined;
|
||||
if (this.props.showContinue !== false) {
|
||||
// XXX: button classes
|
||||
submitButton = (
|
||||
|
@ -462,7 +462,7 @@ export class EmailIdentityAuthEntry extends React.Component<
|
|||
// We only have a session ID if the user has clicked the link in their email,
|
||||
// so show a loading state instead of "an email has been sent to..." because
|
||||
// that's confusing when you've already read that email.
|
||||
if (this.props.inputs.emailAddress === undefined || this.props.stageState?.emailSid) {
|
||||
if (this.props.inputs?.emailAddress === undefined || this.props.stageState?.emailSid) {
|
||||
if (errorSection) {
|
||||
return errorSection;
|
||||
}
|
||||
|
@ -549,13 +549,13 @@ interface IMsisdnAuthEntryProps extends IAuthEntryProps {
|
|||
interface IMsisdnAuthEntryState {
|
||||
token: string;
|
||||
requestingToken: boolean;
|
||||
errorText: string;
|
||||
errorText: string | null;
|
||||
}
|
||||
|
||||
export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsisdnAuthEntryState> {
|
||||
public static LOGIN_TYPE = AuthType.Msisdn;
|
||||
|
||||
private submitUrl: string;
|
||||
private submitUrl?: string;
|
||||
private sid: string;
|
||||
private msisdn: string;
|
||||
|
||||
|
@ -798,11 +798,13 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
public static PHASE_POSTAUTH = 2; // button to confirm SSO completed
|
||||
|
||||
private ssoUrl: string;
|
||||
private popupWindow: Window;
|
||||
private popupWindow: Window | null;
|
||||
|
||||
public constructor(props: ISSOAuthEntryProps) {
|
||||
super(props);
|
||||
|
||||
if (!this.props.authSessionId) throw new Error("This UIA flow requires an authSessionId");
|
||||
|
||||
// We actually send the user through fallback auth so we don't have to
|
||||
// deal with a redirect back to us, losing application context.
|
||||
this.ssoUrl = props.matrixClient.getFallbackAuthUrl(this.props.loginType, this.props.authSessionId);
|
||||
|
@ -858,10 +860,10 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
};
|
||||
|
||||
public render(): React.ReactNode {
|
||||
let continueButton = null;
|
||||
let continueButton: JSX.Element;
|
||||
const cancelButton = (
|
||||
<AccessibleButton
|
||||
onClick={this.props.onCancel}
|
||||
onClick={this.props.onCancel ?? null}
|
||||
kind={this.props.continueKind ? this.props.continueKind + "_outline" : "primary_outline"}
|
||||
>
|
||||
{_t("Cancel")}
|
||||
|
@ -909,7 +911,7 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
}
|
||||
|
||||
export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
|
||||
private popupWindow: Window;
|
||||
private popupWindow: Window | null;
|
||||
private fallbackButton = createRef<HTMLButtonElement>();
|
||||
|
||||
public constructor(props: IAuthEntryProps) {
|
||||
|
@ -927,18 +929,16 @@ export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
|
|||
|
||||
public componentWillUnmount(): void {
|
||||
window.removeEventListener("message", this.onReceiveMessage);
|
||||
if (this.popupWindow) {
|
||||
this.popupWindow.close();
|
||||
}
|
||||
this.popupWindow?.close();
|
||||
}
|
||||
|
||||
public focus = (): void => {
|
||||
if (this.fallbackButton.current) {
|
||||
this.fallbackButton.current.focus();
|
||||
}
|
||||
this.fallbackButton.current?.focus();
|
||||
};
|
||||
|
||||
private onShowFallbackClick = (e: MouseEvent): void => {
|
||||
if (!this.props.authSessionId) return;
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue