1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-07 21:23:00 +03:00

Add utility method mxLoginWithAccessToken to login with existing access token (#7261)

This commit is contained in:
Michael Telatynski
2021-12-02 13:46:44 +00:00
committed by GitHub
parent b69ad0cd0b
commit aa7cae08aa
3 changed files with 18 additions and 3 deletions

View File

@@ -538,8 +538,8 @@ export function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixC
* fires on_logging_in, optionally clears localstorage, persists new credentials
* to localstorage, starts the new client.
*
* @param {MatrixClientCreds} credentials
* @param {Boolean} clearStorage
* @param {IMatrixClientCreds} credentials
* @param {Boolean} clearStorageEnabled
*
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
*/
@@ -918,3 +918,17 @@ export function stopMatrixClient(unsetClient = true): void {
}
}
}
// Utility method to perform a login with an existing access_token
window.mxLoginWithAccessToken = async (hsUrl: string, accessToken: string): Promise<void> => {
const tempClient = createClient({
baseUrl: hsUrl,
accessToken,
});
const { user_id: userId } = await tempClient.whoami();
await doSetLoggedIn({
homeserverUrl: hsUrl,
accessToken,
userId,
}, true);
};