Apply `strictNullChecks` to `src/components/auth/*` (#10484

* Apply `strictNullChecks` to `src/components/auth/*`

* fix

* strict types
pull/28217/head
Michael Telatynski 2023-03-31 09:26:15 +01:00 committed by GitHub
parent af151700c9
commit f152613f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 17 deletions

View File

@ -200,7 +200,7 @@ export function attemptTokenLogin(
}
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) {
logger.warn("Cannot log in with token: can't determine HS URL to use");
Modal.createDialog(ErrorDialog, {

View File

@ -164,7 +164,7 @@ export default class Login {
*/
export async function sendLoginRequest(
hsUrl: string,
isUrl: string,
isUrl: string | undefined,
loginType: string,
loginParams: ILoginParams,
): Promise<IMatrixClientCreds> {
@ -177,11 +177,11 @@ export async function sendLoginRequest(
const wellknown = data.well_known;
if (wellknown) {
if (wellknown["m.homeserver"] && wellknown["m.homeserver"]["base_url"]) {
if (wellknown["m.homeserver"]?.["base_url"]) {
hsUrl = wellknown["m.homeserver"]["base_url"];
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?
isUrl = wellknown["m.identity_server"]["base_url"];
logger.log(`Overrode IS setting with ${isUrl} from login response`);

View File

@ -90,7 +90,7 @@ interface IState {
// used for preserving form values when changing homeserver
username: string;
phoneCountry?: string;
phoneCountry: string;
phoneNumber: string;
// 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,
username: props.defaultUsername ? props.defaultUsername : "",
phoneCountry: "",
phoneNumber: "",
serverIsAlive: true,
@ -217,7 +218,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
let errorText: ReactNode;
// Some error strings only apply for logging in
const usingEmail = username?.indexOf("@") > 0;
const usingEmail = username && username.indexOf("@") > 0;
if (error.httpStatus === 400 && usingEmail) {
errorText = _t("This homeserver does not support login using email address.");
} else if (error.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {

View File

@ -39,8 +39,8 @@ interface IProps {
interface IState {
phase: Phase;
verificationRequest: VerificationRequest;
backupInfo: IKeyBackupInfo;
verificationRequest: VerificationRequest | null;
backupInfo: IKeyBackupInfo | null;
lostKeys: boolean;
}
@ -96,7 +96,7 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
this.props.onFinished();
Modal.createDialog(VerificationRequestDialog, {
verificationRequestPromise: requestPromise,
member: cli.getUser(userId),
member: cli.getUser(userId) ?? undefined,
onFinished: async (): Promise<void> => {
const request = await requestPromise;
request.cancel();
@ -142,15 +142,16 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
};
public render(): React.ReactNode {
const cli = MatrixClientPeg.get();
const { phase, lostKeys } = this.state;
if (this.state.verificationRequest) {
if (this.state.verificationRequest && cli.getUser(this.state.verificationRequest.otherUserId)) {
return (
<EncryptionPanel
layout="dialog"
verificationRequest={this.state.verificationRequest}
onClose={this.onEncryptionPanelClose}
member={MatrixClientPeg.get().getUser(this.state.verificationRequest.otherUserId)}
member={cli.getUser(this.state.verificationRequest.otherUserId)!}
isRoomEncrypted={false}
/>
);

View File

@ -114,7 +114,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
private async initLogin(): Promise<void> {
const queryParams = this.props.realQueryParams;
const hasAllParams = queryParams && queryParams["loginToken"];
const hasAllParams = queryParams?.["loginToken"];
if (hasAllParams) {
this.setState({ loginView: LoginView.Loading });
this.trySsoLogin();
@ -156,7 +156,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
user: MatrixClientPeg.get().getUserId(),
},
password: this.state.password,
device_id: MatrixClientPeg.get().getDeviceId(),
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
};
let credentials: IMatrixClientCreds;
@ -185,11 +185,17 @@ export default class SoftLogout extends React.Component<IProps, IState> {
this.setState({ busy: true });
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 loginType = "m.login.token";
const loginParams = {
token: this.props.realQueryParams["loginToken"],
device_id: MatrixClientPeg.get().getDeviceId(),
device_id: MatrixClientPeg.get().getDeviceId() ?? undefined,
};
let credentials: IMatrixClientCreds;

View File

@ -23,4 +23,4 @@ interface AuthHeaderContextType {
dispatch: Dispatch<ReducerAction<AuthHeaderReducer>>;
}
export const AuthHeaderContext = createContext<AuthHeaderContextType>(undefined);
export const AuthHeaderContext = createContext<AuthHeaderContextType | undefined>(undefined);

View File

@ -29,7 +29,7 @@ export function AuthHeaderDisplay({ title, icon, serverPicker, children }: Props
if (!context) {
return <></>;
}
const current = context.state.length ? context.state[0] : null;
const current = context.state[0] ?? null;
return (
<Fragment>
{current?.icon ?? icon}

View File

@ -27,7 +27,7 @@ interface Props {
export function AuthHeaderModifier(props: Props): null {
const context = useContext(AuthHeaderContext);
const dispatch = context ? context.dispatch : null;
const dispatch = context?.dispatch ?? null;
useEffect(() => {
if (!dispatch) {
return;