diff --git a/src/lib/notification/notification.ts b/src/lib/notification/notification.ts index 1b3728c9d..750c1032a 100644 --- a/src/lib/notification/notification.ts +++ b/src/lib/notification/notification.ts @@ -165,6 +165,7 @@ export const deleteToken = () => { if (window.Notification?.permission !== 'granted') return const firebaseApp = getFirebaseApp() + if (!firebaseApp) return const messaging = getMessaging(firebaseApp) deleteTokenFb(messaging) } diff --git a/src/store/domain/me.ts b/src/store/domain/me.ts index 447a4dd36..a312e2a99 100644 --- a/src/store/domain/me.ts +++ b/src/store/domain/me.ts @@ -7,6 +7,7 @@ import useIndexedDbValue from '/@/composables/utils/useIndexedDbValue' import { deleteToken } from '/@/lib/notification/notification' import { wsListener } from '/@/lib/websocket' import apis from '/@/lib/apis' +import { useRouter } from 'vue-router' export type IDBState = { detail: Readonly | undefined @@ -16,6 +17,7 @@ const useMeStorePinia = defineStore('domain/me', () => { const initialValue: IDBState = { detail: undefined } + const router = useRouter() // TODO: ログインチェック時にrestoreを待つ必要があるかもしれない const [state, restoring, restoringPromise] = useIndexedDbValue( @@ -33,7 +35,7 @@ const useMeStorePinia = defineStore('domain/me', () => { state.detail = data return data } catch { - state.detail = undefined + logout() return undefined } } @@ -47,7 +49,9 @@ const useMeStorePinia = defineStore('domain/me', () => { const onUserUpdated = (userId: UserId) => { if (myId.value !== userId) return - fetchMe() + fetchMe().then(res => { + if (res === undefined) router.push('/login') + }) } wsListener.on('USER_UPDATED', ({ id }) => { onUserUpdated(id) @@ -56,7 +60,9 @@ const useMeStorePinia = defineStore('domain/me', () => { onUserUpdated(id) }) wsListener.on('reconnect', () => { - fetchMe() + fetchMe().then(res => { + if (res === undefined) router.push('/login') + }) }) return {