From fbfb0f4729cc10450f13c668d06e5966a51df74c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Mar 2024 15:44:54 +0000 Subject: [PATCH] Shuttle secrets via credentials and avoid calling doSetLoggedIn twice Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Lifecycle.ts | 8 ++------ src/MatrixClientPeg.ts | 1 + src/components/views/auth/LoginWithQR.tsx | 10 +++------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 07ab1f81f7..827e58c33f 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -798,11 +798,7 @@ async function createOidcTokenRefresher(credentials: IMatrixClientCreds): Promis * * @returns {Promise} promise which resolves to the new MatrixClient once it has been started */ -async function doSetLoggedIn( - credentials: IMatrixClientCreds, - clearStorageEnabled: boolean, - secrets?: QRSecretsBundle, -): Promise { +async function doSetLoggedIn(credentials: IMatrixClientCreds, clearStorageEnabled: boolean): Promise { checkSessionLock(); credentials.guest = Boolean(credentials.guest); @@ -873,7 +869,7 @@ async function doSetLoggedIn( checkSessionLock(); dis.fire(Action.OnLoggedIn); - await startMatrixClient(client, /*startSyncing=*/ !softLogout, secrets); + await startMatrixClient(client, /*startSyncing=*/ !softLogout, credentials.secrets); return client; } diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index 763b0ad4d1..b7bdacb085 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -66,6 +66,7 @@ export interface IMatrixClientCreds { guest?: boolean; pickleKey?: string; freshLogin?: boolean; + secrets?: QRSecretsBundle; } /** diff --git a/src/components/views/auth/LoginWithQR.tsx b/src/components/views/auth/LoginWithQR.tsx index 6d51a28170..32a0a11723 100644 --- a/src/components/views/auth/LoginWithQR.tsx +++ b/src/components/views/auth/LoginWithQR.tsx @@ -27,7 +27,7 @@ import type { MSC4108SignInWithQR } from "matrix-js-sdk/src/rendezvous"; import LoginWithQRFlow from "./LoginWithQRFlow"; import { getOidcClientId } from "../../../utils/oidc/registerClient"; import SdkConfig from "../../../SdkConfig"; -import { completeDeviceAuthorizationGrant, completeLoginWithQr } from "../../../Lifecycle"; +import { completeDeviceAuthorizationGrant } from "../../../Lifecycle"; /** * The intention of this enum is to have a mode that scans a QR code instead of generating one. @@ -284,10 +284,8 @@ export default class LoginWithQR extends React.Component { // wait for secrets: const { secrets } = await rendezvous.loginStep5(credentials.deviceId); - await completeLoginWithQr(credentials, secrets); - // done - this.props.onFinished(credentials); + this.props.onFinished({ ...credentials, secrets }); } else { // MSC4108-Flow: ExistingScanned const homeserverBaseUrl = homeserverBaseUrlFromStep1; @@ -354,10 +352,8 @@ export default class LoginWithQR extends React.Component { // wait for secrets const { secrets } = await this.state.rendezvous.loginStep5(credentials.deviceId); - await completeLoginWithQr(credentials, secrets); - // done - this.props.onFinished(credentials); + this.props.onFinished({ ...credentials, secrets }); } };