ModuleAPI: overwrite_login action was not stopping the existing client resulting in the action failing with rust-sdk (#12272)

* Fix overwrite login action not stopping client

* remove unneeded fixture for overwrite login test

* Fix playwrite bad import of app sources

* revert uneeded change on fore OnLoggedIn causing side effects

* Add unit test for overwrite login action

* remove un needed ts-ignore
This commit is contained in:
Valere
2024-02-22 16:41:21 +01:00
committed by GitHub
parent b9bdd18666
commit 8a70260c81
4 changed files with 146 additions and 5 deletions

View File

@@ -97,8 +97,20 @@ dis.register((payload) => {
onLoggedOut();
} else if (payload.action === Action.OverwriteLogin) {
const typed = <OverwriteLoginPayload>payload;
// noinspection JSIgnoredPromiseFromCall - we don't care if it fails
doSetLoggedIn(typed.credentials, true);
// Stop the current client before overwriting the login.
// If not done it might be impossible to clear the storage, as the
// rust crypto backend might be holding an open connection to the indexeddb store.
// We also use the `unsetClient` flag to false, because at this point we are
// already in the logged in flows of the `MatrixChat` component, and it will
// always expect to have a client (calls to `MatrixClientPeg.safeGet()`).
// If we unset the client and the component is updated, the render will fail and unmount everything.
// (The module dialog closes and fires a `aria_unhide_main_app` that will trigger a re-render)
stopMatrixClient(false);
doSetLoggedIn(typed.credentials, true).catch((e) => {
// XXX we might want to fire a new event here to let the app know that the login failed ?
// The module api could use it to display a message to the user.
logger.warn("Failed to overwrite login", e);
});
}
});

View File

@@ -160,6 +160,12 @@ export class ProxiedModuleApi implements ModuleApi {
* @override
*/
public async overwriteAccountAuth(accountInfo: AccountAuthInfo): Promise<void> {
// We want to wait for the new login to complete before returning.
// See `Action.OnLoggedIn` in dispatcher.
const awaitNewLogin = new Promise<void>((resolve) => {
this.overrideLoginResolve = resolve;
});
dispatcher.dispatch<OverwriteLoginPayload>(
{
action: Action.OverwriteLogin,
@@ -172,9 +178,7 @@ export class ProxiedModuleApi implements ModuleApi {
); // require to be sync to match inherited interface behaviour
// wait for login to complete
await new Promise<void>((resolve) => {
this.overrideLoginResolve = resolve;
});
await awaitNewLogin;
}
/**