Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit aa7cae0

Browse files
authored
Add utility method mxLoginWithAccessToken to login with existing access token (#7261)
1 parent b69ad0c commit aa7cae0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/@types/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ declare global {
100100
mxOnRecaptchaLoaded?: () => void;
101101
electron?: Electron;
102102
mxSendSentryReport: (userText: string, issueUrl: string, error: Error) => Promise<void>;
103+
mxLoginWithAccessToken: (hsUrl: string, accessToken: string) => Promise<void>;
103104
}
104105

105106
interface DesktopCapturerSource {

src/Lifecycle.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ export function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixC
538538
* fires on_logging_in, optionally clears localstorage, persists new credentials
539539
* to localstorage, starts the new client.
540540
*
541-
* @param {MatrixClientCreds} credentials
542-
* @param {Boolean} clearStorage
541+
* @param {IMatrixClientCreds} credentials
542+
* @param {Boolean} clearStorageEnabled
543543
*
544544
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
545545
*/
@@ -918,3 +918,17 @@ export function stopMatrixClient(unsetClient = true): void {
918918
}
919919
}
920920
}
921+
922+
// Utility method to perform a login with an existing access_token
923+
window.mxLoginWithAccessToken = async (hsUrl: string, accessToken: string): Promise<void> => {
924+
const tempClient = createClient({
925+
baseUrl: hsUrl,
926+
accessToken,
927+
});
928+
const { user_id: userId } = await tempClient.whoami();
929+
await doSetLoggedIn({
930+
homeserverUrl: hsUrl,
931+
accessToken,
932+
userId,
933+
}, true);
934+
};

src/MatrixClientPeg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
4040

4141
export interface IMatrixClientCreds {
4242
homeserverUrl: string;
43-
identityServerUrl: string;
43+
identityServerUrl?: string;
4444
userId: string;
4545
deviceId?: string;
4646
accessToken: string;

0 commit comments

Comments
 (0)