Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自分が消える問題を修正 #4400

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/notification/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 9 additions & 3 deletions src/store/domain/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyUserDetail> | undefined
Expand All @@ -16,6 +17,7 @@ const useMeStorePinia = defineStore('domain/me', () => {
const initialValue: IDBState = {
detail: undefined
}
const router = useRouter()

// TODO: ログインチェック時にrestoreを待つ必要があるかもしれない
const [state, restoring, restoringPromise] = useIndexedDbValue(
Expand All @@ -33,7 +35,7 @@ const useMeStorePinia = defineStore('domain/me', () => {
state.detail = data
return data
} catch {
state.detail = undefined
logout()
return undefined
}
}
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
Loading