From aa7cae08aa11e98d71400df9448a65aa0c2e4b41 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 2 Dec 2021 13:46:44 +0000 Subject: [PATCH] Add utility method mxLoginWithAccessToken to login with existing access token (#7261) --- src/@types/global.d.ts | 1 + src/Lifecycle.ts | 18 ++++++++++++++++-- src/MatrixClientPeg.ts | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 43c30c94b8..ed14483fb6 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -100,6 +100,7 @@ declare global { mxOnRecaptchaLoaded?: () => void; electron?: Electron; mxSendSentryReport: (userText: string, issueUrl: string, error: Error) => Promise; + mxLoginWithAccessToken: (hsUrl: string, accessToken: string) => Promise; } interface DesktopCapturerSource { diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 8477116104..ef7b7b33de 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -538,8 +538,8 @@ export function hydrateSession(credentials: IMatrixClientCreds): Promise => { + const tempClient = createClient({ + baseUrl: hsUrl, + accessToken, + }); + const { user_id: userId } = await tempClient.whoami(); + await doSetLoggedIn({ + homeserverUrl: hsUrl, + accessToken, + userId, + }, true); +}; diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index 978939e707..c6da0ed831 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger"; export interface IMatrixClientCreds { homeserverUrl: string; - identityServerUrl: string; + identityServerUrl?: string; userId: string; deviceId?: string; accessToken: string;