Overwrite the old session if the new creds are for a different user
Fixes https://github.com/vector-im/riot-web/issues/10272pull/21833/head
parent
8b417f8a60
commit
fca4ebcd72
|
@ -348,15 +348,26 @@ export function setLoggedIn(credentials) {
|
|||
* new one in its place. This additionally starts all other react-sdk services
|
||||
* which use the new Matrix client.
|
||||
*
|
||||
* If the credentials belong to a different user from the session already stored,
|
||||
* the old session will be cleared automatically.
|
||||
*
|
||||
* @param {MatrixClientCreds} credentials The credentials to use
|
||||
*
|
||||
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
|
||||
*/
|
||||
export function hydrateSession(credentials) {
|
||||
stopMatrixClient();
|
||||
const oldUserId = MatrixClientPeg.get().getUserId();
|
||||
|
||||
stopMatrixClient(); // unsets MatrixClientPeg.get()
|
||||
localStorage.removeItem("mx_soft_logout");
|
||||
_isLoggingOut = false;
|
||||
return _doSetLoggedIn(credentials, false);
|
||||
|
||||
const overwrite = credentials.userId !== oldUserId;
|
||||
if (overwrite) {
|
||||
console.warn("Rehydrating the user's session with a different user's - clearing all data");
|
||||
}
|
||||
|
||||
return _doSetLoggedIn(credentials, overwrite);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue