Merge pull request #518 from robintown/logout-lost-sessions
Log out lost sessions
This commit is contained in:
commit
8f95da4b07
1 changed files with 42 additions and 18 deletions
|
@ -33,6 +33,7 @@ import {
|
||||||
initClient,
|
initClient,
|
||||||
initMatroskaClient,
|
initMatroskaClient,
|
||||||
defaultHomeserver,
|
defaultHomeserver,
|
||||||
|
CryptoStoreIntegrityError,
|
||||||
} from "./matrix-utils";
|
} from "./matrix-utils";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -115,28 +116,51 @@ export const ClientProvider: FC<Props> = ({ children }) => {
|
||||||
// We're running as a standalone application
|
// We're running as a standalone application
|
||||||
try {
|
try {
|
||||||
const session = loadSession();
|
const session = loadSession();
|
||||||
|
if (!session) return { client: undefined, isPasswordlessUser: false };
|
||||||
|
|
||||||
if (session) {
|
logger.log("Using a standalone client");
|
||||||
/* eslint-disable camelcase */
|
|
||||||
const { user_id, device_id, access_token, passwordlessUser } =
|
|
||||||
session;
|
|
||||||
|
|
||||||
logger.log("Using a standalone client");
|
/* eslint-disable camelcase */
|
||||||
const client = await initClient(
|
const { user_id, device_id, access_token, passwordlessUser } =
|
||||||
{
|
session;
|
||||||
baseUrl: defaultHomeserver,
|
|
||||||
accessToken: access_token,
|
|
||||||
userId: user_id,
|
|
||||||
deviceId: device_id,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
/* eslint-enable camelcase */
|
|
||||||
|
|
||||||
return { client, isPasswordlessUser: passwordlessUser };
|
try {
|
||||||
|
return {
|
||||||
|
client: await initClient(
|
||||||
|
{
|
||||||
|
baseUrl: defaultHomeserver,
|
||||||
|
accessToken: access_token,
|
||||||
|
userId: user_id,
|
||||||
|
deviceId: device_id,
|
||||||
|
},
|
||||||
|
true
|
||||||
|
),
|
||||||
|
isPasswordlessUser: passwordlessUser,
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof CryptoStoreIntegrityError) {
|
||||||
|
// We can't use this session anymore, so let's log it out
|
||||||
|
try {
|
||||||
|
const client = await initClient(
|
||||||
|
{
|
||||||
|
baseUrl: defaultHomeserver,
|
||||||
|
accessToken: access_token,
|
||||||
|
userId: user_id,
|
||||||
|
deviceId: device_id,
|
||||||
|
},
|
||||||
|
false // Don't need the crypto store just to log out
|
||||||
|
);
|
||||||
|
await client.logout(undefined, true);
|
||||||
|
} catch (err_) {
|
||||||
|
logger.warn(
|
||||||
|
"The previous session was lost, and we couldn't log it out, " +
|
||||||
|
"either"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
|
/* eslint-enable camelcase */
|
||||||
return { client: undefined, isPasswordlessUser: false };
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
clearSession();
|
clearSession();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
Loading…
Reference in a new issue