diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index 9006150bc83e..17d690cd3a93 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -7,6 +7,7 @@ import { defineAsyncComponent, reactive, ref } from 'vue'; import * as Misskey from 'misskey-js'; import { apiUrl } from '@@/js/config.js'; import type { MenuItem, MenuButton } from '@/types/menu.js'; +import { defaultMemoryStorage } from '@/memory-storage'; import { showSuspendedDialog } from '@/scripts/show-suspended-dialog.js'; import { i18n } from '@/i18n.js'; import { miLocalStorage } from '@/local-storage.js'; @@ -40,6 +41,8 @@ export function incNotesCount() { export async function signout() { if (!$i) return; + defaultMemoryStorage.clear(); + waiting(); document.cookie.split(';').forEach((cookie) => { const cookieName = cookie.split('=')[0].trim(); @@ -107,7 +110,7 @@ export async function removeAccount(idOrToken: Account['id']) { } function fetchAccount(token: string, id?: string, forceShowDialog?: boolean): Promise { - document.cookie = "token=; path=/; max-age=0"; + document.cookie = 'token=; path=/; max-age=0'; document.cookie = `token=${token}; path=/queue; max-age=86400; SameSite=Strict; Secure`; // bull dashboardの認証とかで使う return new Promise((done, fail) => { diff --git a/packages/frontend/src/memory-storage.ts b/packages/frontend/src/memory-storage.ts new file mode 100644 index 000000000000..d1d410e1193d --- /dev/null +++ b/packages/frontend/src/memory-storage.ts @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export type MemoryStorage = { + has: (key: string) => boolean; + getItem: (key: string) => T | null; + setItem: (key: string, value: unknown) => void; + removeItem: (key: string) => void; + clear: () => void; + size: number; +}; + +class MemoryStorageImpl implements MemoryStorage { + private readonly storage: Map; + + constructor() { + this.storage = new Map(); + } + + has(key: string): boolean { + return this.storage.has(key); + } + + getItem(key: string): T | null { + return this.storage.has(key) ? this.storage.get(key) as T : null; + } + + setItem(key: string, value: unknown): void { + this.storage.set(key, value); + } + + removeItem(key: string): void { + this.storage.delete(key); + } + + clear(): void { + this.storage.clear(); + } + + get size(): number { + return this.storage.size; + } +} + +export function createMemoryStorage(): MemoryStorage { + return new MemoryStorageImpl(); +} + +export const defaultMemoryStorage: MemoryStorage = createMemoryStorage(); diff --git a/packages/frontend/src/pages/admin/users.vue b/packages/frontend/src/pages/admin/users.vue index c9c3d16a2f6e..91104b676d49 100644 --- a/packages/frontend/src/pages/admin/users.vue +++ b/packages/frontend/src/pages/admin/users.vue @@ -62,6 +62,7 @@ SPDX-License-Identifier: AGPL-3.0-only