Apply `strictNullChecks` to `src/components/auth/*` (#10484
* Apply `strictNullChecks` to `src/components/auth/*` * fix * strict typespull/28217/head
parent
af151700c9
commit
f152613f83
|
@ -200,7 +200,7 @@ export function attemptTokenLogin(
|
||||||
}
|
}
|
||||||
|
|
||||||
const homeserver = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
const homeserver = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
||||||
const identityServer = localStorage.getItem(SSO_ID_SERVER_URL_KEY);
|
const identityServer = localStorage.getItem(SSO_ID_SERVER_URL_KEY) ?? undefined;
|
||||||
if (!homeserver) {
|
if (!homeserver) {
|
||||||
logger.warn("Cannot log in with token: can't determine HS URL to use");
|
logger.warn("Cannot log in with token: can't determine HS URL to use");
|
||||||
Modal.createDialog(ErrorDialog, {
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
|
|
@ -164,7 +164,7 @@ export default class Login {
|
||||||
*/
|
*/
|
||||||
export async function sendLoginRequest(
|
export async function sendLoginRequest(
|
||||||
hsUrl: string,
|
hsUrl: string,
|
||||||
isUrl: string,
|
isUrl: string | undefined,
|
||||||
loginType: string,
|
loginType: string,
|
||||||
loginParams: ILoginParams,
|
loginParams: ILoginParams,
|
||||||
): Promise<IMatrixClientCreds> {
|
): Promise<IMatrixClientCreds> {
|
||||||
|
@ -177,11 +177,11 @@ export async function sendLoginRequest(
|
||||||
|
|
||||||
const wellknown = data.well_known;
|
const wellknown = data.well_known;
|
||||||
if (wellknown) {
|
if (wellknown) {
|
||||||
if (wellknown["m.homeserver"] && wellknown["m.homeserver"]["base_url"]) {
|
if (wellknown["m.homeserver"]?.["base_url"]) {
|
||||||
hsUrl = wellknown["m.homeserver"]["base_url"];
|
hsUrl = wellknown["m.homeserver"]["base_url"];
|
||||||
logger.log(`Overrode homeserver setting with ${hsUrl} from login response`);
|
logger.log(`Overrode homeserver setting with ${hsUrl} from login response`);
|
||||||
}
|
}
|
||||||
if (wellknown["m.identity_server"] && wellknown["m.identity_server"]["base_url"]) {
|
if (wellknown["m.identity_server"]?.["base_url"]) {
|
||||||
// TODO: should we prompt here?
|
// TODO: should we prompt here?
|
||||||
isUrl = wellknown["m.identity_server"]["base_url"];
|
isUrl = wellknown["m.identity_server"]["base_url"];
|
||||||
logger.log(`Overrode IS setting with ${isUrl} from login response`);
|
logger.log(`Overrode IS setting with ${isUrl} from login response`);
|
||||||
|
|
|
@ -90,7 +90,7 @@ interface IState {
|
||||||
|
|
||||||
// used for preserving form values when changing homeserver
|
// used for preserving form values when changing homeserver
|
||||||
username: string;
|
username: string;
|
||||||
phoneCountry?: string;
|
phoneCountry: string;
|
||||||
phoneNumber: string;
|
phoneNumber: string;
|
||||||
|
|
||||||
// We perform liveliness checks later, but for now suppress the errors.
|
// We perform liveliness checks later, but for now suppress the errors.
|
||||||
|
@ -126,6 +126,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
||||||
canTryLogin: true,
|
canTryLogin: true,
|
||||||
|
|
||||||
username: props.defaultUsername ? props.defaultUsername : "",
|
username: props.defaultUsername ? props.defaultUsername : "",
|
||||||
|
phoneCountry: "",
|
||||||
phoneNumber: "",
|
phoneNumber: "",
|
||||||
|
|
||||||
serverIsAlive: true,
|
serverIsAlive: true,
|
||||||
|
@ -217,7 +218,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
||||||
let errorText: ReactNode;
|
let errorText: ReactNode;
|
||||||
|
|
||||||
// Some error strings only apply for logging in
|
// Some error strings only apply for logging in
|
||||||
const usingEmail = username?.indexOf("@") > 0;
|
const usingEmail = username && username.indexOf("@") > 0;
|
||||||
if (error.httpStatus === 400 && usingEmail) {
|
if (error.httpStatus === 400 && usingEmail) {
|
||||||
errorText = _t("This homeserver does not support login using email address.");
|
errorText = _t("This homeserver does not support login using email address.");
|
||||||
} else if (error.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {
|
} else if (error.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {
|
||||||
|
|
|
@ -39,8 +39,8 @@ interface IProps {
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
phase: Phase;
|
phase: Phase;
|
||||||
verificationRequest: VerificationRequest;
|
verificationRequest: VerificationRequest | null;
|
||||||
backupInfo: IKeyBackupInfo;
|
backupInfo: IKeyBackupInfo | null;
|
||||||
lostKeys: boolean;
|
lostKeys: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
|
||||||
this.props.onFinished();
|
this.props.onFinished();
|
||||||
Modal.createDialog(VerificationRequestDialog, {
|
Modal.createDialog(VerificationRequestDialog, {
|
||||||
verificationRequestPromise: requestPromise,
|
verificationRequestPromise: requestPromise,
|
||||||
member: cli.getUser(userId),
|
member: cli.getUser(userId) ?? undefined,
|
||||||
onFinished: async (): Promise<void> => {
|
onFinished: async (): Promise<void> => {
|
||||||
const request = await requestPromise;
|
const request = await requestPromise;
|
||||||
request.cancel();
|
request.cancel();
|
||||||
|
@ -142,15 +142,16 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
|
||||||
};
|
};
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
const { phase, lostKeys } = this.state;
|
const { phase, lostKeys } = this.state;
|
||||||
|
|
||||||
if (this.state.verificationRequest) {
|
if (this.state.verificationRequest && cli.getUser(this.state.verificationRequest.otherUserId)) {
|
||||||
return (
|
return (
|
||||||
<EncryptionPanel
|
<EncryptionPanel
|
||||||
layout="dialog"
|
layout="dialog"
|
||||||
verificationRequest={this.state.verificationRequest}
|
verificationRequest={this.state.verificationRequest}
|
||||||
onClose={this.onEncryptionPanelClose}
|
onClose={this.onEncryptionPanelClose}
|
||||||
member={MatrixClientPeg.get().getUser(this.state.verificationRequest.otherUserId)}
|
member={cli.getUser(this.state.verificationRequest.otherUserId)!}
|
||||||
isRoomEncrypted={false}
|
isRoomEncrypted={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -114,7 +114,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
|
|
||||||
private async initLogin(): Promise<void> {
|
private async initLogin(): Promise<void> {
|
||||||
const queryParams = this.props.realQueryParams;
|
const queryParams = this.props.realQueryParams;
|
||||||
const hasAllParams = queryParams && queryParams["loginToken"];
|
const hasAllParams = queryParams?.["loginToken"];
|
||||||
if (hasAllParams) {
|
if (hasAllParams) {
|
||||||
this.setState({ loginView: LoginView.Loading });
|
this.setState({ loginView: LoginView.Loading });
|
||||||
this.trySsoLogin();
|
this.trySsoLogin();
|
||||||
|
@ -156,7 +156,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
user: MatrixClientPeg.get().getUserId(),
|
user: MatrixClientPeg.get().getUserId(),
|
||||||
},
|
},
|
||||||
password: this.state.password,
|
password: this.state.password,
|
||||||
device_id: MatrixClientPeg.get().getDeviceId(),
|
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
let credentials: IMatrixClientCreds;
|
let credentials: IMatrixClientCreds;
|
||||||
|
@ -185,11 +185,17 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
this.setState({ busy: true });
|
this.setState({ busy: true });
|
||||||
|
|
||||||
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
||||||
|
if (!hsUrl) {
|
||||||
|
logger.error("Homeserver URL unknown for SSO login callback");
|
||||||
|
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
|
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
|
||||||
const loginType = "m.login.token";
|
const loginType = "m.login.token";
|
||||||
const loginParams = {
|
const loginParams = {
|
||||||
token: this.props.realQueryParams["loginToken"],
|
token: this.props.realQueryParams["loginToken"],
|
||||||
device_id: MatrixClientPeg.get().getDeviceId(),
|
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
let credentials: IMatrixClientCreds;
|
let credentials: IMatrixClientCreds;
|
||||||
|
|
|
@ -23,4 +23,4 @@ interface AuthHeaderContextType {
|
||||||
dispatch: Dispatch<ReducerAction<AuthHeaderReducer>>;
|
dispatch: Dispatch<ReducerAction<AuthHeaderReducer>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AuthHeaderContext = createContext<AuthHeaderContextType>(undefined);
|
export const AuthHeaderContext = createContext<AuthHeaderContextType | undefined>(undefined);
|
||||||
|
|
|
@ -29,7 +29,7 @@ export function AuthHeaderDisplay({ title, icon, serverPicker, children }: Props
|
||||||
if (!context) {
|
if (!context) {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
const current = context.state.length ? context.state[0] : null;
|
const current = context.state[0] ?? null;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{current?.icon ?? icon}
|
{current?.icon ?? icon}
|
||||||
|
|
|
@ -27,7 +27,7 @@ interface Props {
|
||||||
|
|
||||||
export function AuthHeaderModifier(props: Props): null {
|
export function AuthHeaderModifier(props: Props): null {
|
||||||
const context = useContext(AuthHeaderContext);
|
const context = useContext(AuthHeaderContext);
|
||||||
const dispatch = context ? context.dispatch : null;
|
const dispatch = context?.dispatch ?? null;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!dispatch) {
|
if (!dispatch) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue