Conform more of the codebase with strictNullChecks
(#10703)
This commit is contained in:
parent
db40479910
commit
619a9e8542
24 changed files with 108 additions and 77 deletions
|
@ -176,7 +176,7 @@ export async function loadSession(opts: ILoadSessionOpts = {}): Promise<boolean>
|
|||
*/
|
||||
export async function getStoredSessionOwner(): Promise<[string, boolean] | [null, null]> {
|
||||
const { hsUrl, userId, hasAccessToken, isGuest } = await getStoredSessionVars();
|
||||
return hsUrl && userId && hasAccessToken ? [userId, isGuest] : [null, null];
|
||||
return hsUrl && userId && hasAccessToken ? [userId, !!isGuest] : [null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,9 +343,9 @@ export interface IStoredSession {
|
|||
* may not be valid, as it is not tested for consistency here.
|
||||
* @returns {Object} Information about the session - see implementation for variables.
|
||||
*/
|
||||
export async function getStoredSessionVars(): Promise<IStoredSession> {
|
||||
const hsUrl = localStorage.getItem(HOMESERVER_URL_KEY);
|
||||
const isUrl = localStorage.getItem(ID_SERVER_URL_KEY);
|
||||
export async function getStoredSessionVars(): Promise<Partial<IStoredSession>> {
|
||||
const hsUrl = localStorage.getItem(HOMESERVER_URL_KEY) ?? undefined;
|
||||
const isUrl = localStorage.getItem(ID_SERVER_URL_KEY) ?? undefined;
|
||||
let accessToken: string | undefined;
|
||||
try {
|
||||
accessToken = await StorageManager.idbLoad("account", "mx_access_token");
|
||||
|
@ -367,8 +367,8 @@ export async function getStoredSessionVars(): Promise<IStoredSession> {
|
|||
// if we pre-date storing "mx_has_access_token", but we retrieved an access
|
||||
// token, then we should say we have an access token
|
||||
const hasAccessToken = localStorage.getItem("mx_has_access_token") === "true" || !!accessToken;
|
||||
const userId = localStorage.getItem("mx_user_id");
|
||||
const deviceId = localStorage.getItem("mx_device_id");
|
||||
const userId = localStorage.getItem("mx_user_id") ?? undefined;
|
||||
const deviceId = localStorage.getItem("mx_device_id") ?? undefined;
|
||||
|
||||
let isGuest: boolean;
|
||||
if (localStorage.getItem("mx_is_guest") !== null) {
|
||||
|
@ -447,7 +447,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
|
|||
}
|
||||
|
||||
let decryptedAccessToken = accessToken;
|
||||
const pickleKey = await PlatformPeg.get()?.getPickleKey(userId, deviceId);
|
||||
const pickleKey = await PlatformPeg.get()?.getPickleKey(userId, deviceId ?? "");
|
||||
if (pickleKey) {
|
||||
logger.log("Got pickle key");
|
||||
if (typeof accessToken !== "string") {
|
||||
|
@ -740,7 +740,7 @@ export function logout(): void {
|
|||
|
||||
_isLoggingOut = true;
|
||||
const client = MatrixClientPeg.get();
|
||||
PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId());
|
||||
PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId() ?? "");
|
||||
client.logout(true).then(onLoggedOut, (err) => {
|
||||
// Just throwing an error here is going to be very unhelpful
|
||||
// if you're trying to log out because your server's down and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue