Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Remove remaining old dehydration
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Oct 10, 2024
1 parent d98a7f5 commit 7fa97d4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 46 deletions.
37 changes: 0 additions & 37 deletions src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,43 +664,6 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise<Matr
return doSetLoggedIn(Object.assign({}, credentials, { pickleKey }), true, true);
}

/**
* Hydrates an existing session by using the credentials provided. This will
* not clear any local storage, unlike setLoggedIn().
*
* Stops the existing Matrix client (without clearing its data) and starts a
* 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 {IMatrixClientCreds} credentials The credentials to use
*
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
*/
export async function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixClient> {
const oldUserId = MatrixClientPeg.safeGet().getUserId();
const oldDeviceId = MatrixClientPeg.safeGet().getDeviceId();

stopMatrixClient(); // unsets MatrixClientPeg.get()
localStorage.removeItem("mx_soft_logout");
_isLoggingOut = false;

const overwrite = credentials.userId !== oldUserId || credentials.deviceId !== oldDeviceId;
if (overwrite) {
logger.warn("Clearing all data: Old session belongs to a different user/session");
}

if (!credentials.pickleKey && credentials.deviceId !== undefined) {
logger.info("Lifecycle#hydrateSession: Pickle key not provided - trying to get one");
credentials.pickleKey =
(await PlatformPeg.get()?.getPickleKey(credentials.userId, credentials.deviceId)) ?? undefined;
}

return doSetLoggedIn(credentials, overwrite, false);
}

/**
* When we have a authenticated via OIDC-native flow and have a refresh token
* try to create a token refresher.
Expand Down
7 changes: 0 additions & 7 deletions src/SecurityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ async function doAccessSecretStorage(func: () => Promise<void>, forceReset: bool
});
logger.debug("accessSecretStorage: bootstrapSecretStorage");
await crypto.bootstrapSecretStorage({});

const keyId = Object.keys(secretStorageKeys)[0];
if (!keyId) {
logger.warn("accessSecretStorage: Not setting dehydration key: no SSSS key found");
} else {
logger.log("accessSecretStorage: Not setting dehydration key: feature disabled");
}
}

logger.debug("accessSecretStorage: 4S now ready");
Expand Down
4 changes: 2 additions & 2 deletions src/components/structures/auth/SoftLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
return;
}

Lifecycle.hydrateSession(credentials).catch((e) => {
Lifecycle.setLoggedIn(credentials).catch((e) => {
logger.error(e);
this.setState({ busy: false, errorText: _t("auth|failed_soft_logout_auth") });
});
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
return false;
}

return Lifecycle.hydrateSession(credentials)
return Lifecycle.setLoggedIn(credentials)
.then(() => {
if (this.props.onTokenLoginCompleted) {
this.props.onTokenLoginCompleted();
Expand Down

0 comments on commit 7fa97d4

Please sign in to comment.