mirror of
https://github.com/ente-io/ente.git
synced 2025-07-25 11:05:15 +00:00
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { clearBlobCaches } from "@/base/blob-cache";
|
|
import { clearKVDB } from "@/base/kv";
|
|
import { clearLocalStorage } from "@/base/local-storage";
|
|
import log from "@/base/log";
|
|
import localForage from "@ente/shared/storage/localForage";
|
|
import { clearKeys } from "@ente/shared/storage/sessionStorage";
|
|
import { logout as remoteLogout } from "../api/user";
|
|
import { clearStashedRedirect } from "./redirect";
|
|
|
|
/**
|
|
* Logout sequence common to all apps that rely on the accounts package.
|
|
*
|
|
* [Note: Do not throw during logout]
|
|
*
|
|
* This function is guaranteed to not thrown any errors, and will try to
|
|
* independently complete all the steps in the sequence that can be completed.
|
|
* This allows the user to logout and start again even if somehow their account
|
|
* gets in an unexpected state.
|
|
*/
|
|
export const accountLogout = async () => {
|
|
const ignoreError = (label: string, e: unknown) =>
|
|
log.error(`Ignoring error during logout (${label})`, e);
|
|
|
|
log.info("logout (account)");
|
|
|
|
try {
|
|
await remoteLogout();
|
|
} catch (e) {
|
|
ignoreError("Remote", e);
|
|
}
|
|
try {
|
|
clearStashedRedirect();
|
|
} catch (e) {
|
|
ignoreError("In-memory store", e);
|
|
}
|
|
try {
|
|
clearKeys();
|
|
} catch (e) {
|
|
ignoreError("Session storage", e);
|
|
}
|
|
try {
|
|
clearLocalStorage();
|
|
} catch (e) {
|
|
ignoreError("Local storage", e);
|
|
}
|
|
try {
|
|
await localForage.clear();
|
|
} catch (e) {
|
|
ignoreError("Local forage", e);
|
|
}
|
|
try {
|
|
await clearBlobCaches();
|
|
} catch (e) {
|
|
ignoreError("Blob cache", e);
|
|
}
|
|
try {
|
|
await clearKVDB();
|
|
} catch (e) {
|
|
ignoreError("KV DB", e);
|
|
}
|
|
};
|