ente/packages/accounts/services/user.ts

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-11-02 05:26:51 +00:00
import InMemoryStore from '@ente/shared/storage/InMemoryStore';
import { _logout } from '../api/user';
import { PAGES } from '../constants/pages';
import { clearKeys } from '@ente/shared/storage/sessionStorage';
import { clearData } from '@ente/shared/storage/localStorage';
2023-11-10 09:38:10 +00:00
import { deleteAllCache } from '@ente/shared/storage/cacheStorage/helpers';
import { logError } from '@ente/shared/sentry';
2023-11-02 15:51:48 +00:00
import { clearFiles } from '@ente/shared/storage/localForage/helpers';
import router from 'next/router';
2023-11-03 04:19:02 +00:00
import isElectron from 'is-electron';
2023-11-10 09:38:10 +00:00
import ElectronAPIs from '@ente/shared/electron';
import { Events, eventBus } from '@ente/shared/events';
2023-11-02 05:26:51 +00:00
2023-11-02 15:51:48 +00:00
export const logoutUser = async () => {
2023-11-02 05:26:51 +00:00
try {
try {
await _logout();
} catch (e) {
// ignore
}
try {
InMemoryStore.clear();
} catch (e) {
// ignore
2023-11-02 15:22:31 +00:00
logError(e, 'clear InMemoryStore failed');
2023-11-02 05:26:51 +00:00
}
try {
clearKeys();
} catch (e) {
2023-11-02 15:22:31 +00:00
logError(e, 'clearKeys failed');
2023-11-02 05:26:51 +00:00
}
try {
clearData();
} catch (e) {
2023-11-02 15:22:31 +00:00
logError(e, 'clearData failed');
2023-11-02 05:26:51 +00:00
}
2023-11-10 09:38:10 +00:00
try {
await deleteAllCache();
} catch (e) {
logError(e, 'deleteAllCache failed');
}
2023-11-02 15:51:48 +00:00
try {
await clearFiles();
} catch (e) {
logError(e, 'clearFiles failed');
}
2023-11-03 04:19:02 +00:00
if (isElectron()) {
try {
ElectronAPIs.clearElectronStore();
} catch (e) {
logError(e, 'clearElectronStore failed');
}
}
2023-11-10 09:38:10 +00:00
try {
eventBus.emit(Events.LOGOUT);
} catch (e) {
logError(e, 'Error in logout handlers');
}
2023-11-02 05:26:51 +00:00
router.push(PAGES.ROOT);
} catch (e) {
2023-11-02 15:22:31 +00:00
logError(e, 'logoutUser failed');
2023-11-02 05:26:51 +00:00
}
};