Clarify auth states

This commit is contained in:
2026-08-14 13:29:26 +09:00
parent cbd43e16c2
commit c4072ed86b
5 changed files with 45 additions and 8 deletions

View File

@@ -2,6 +2,8 @@ export default defineNuxtRouteMiddleware(async (to) => {
if (to.path === '/login' || to.path.startsWith('/share/')) return
const session = useState<{ id: string; email: string; name: string } | null>('session')
const sessionCookie = useCookie<string | null>('money_session')
const authReason = sessionCookie.value ? 'expired' : 'required'
if (session.value === undefined) {
try {
@@ -12,6 +14,12 @@ export default defineNuxtRouteMiddleware(async (to) => {
}
if (!session.value) {
return navigateTo('/login')
return navigateTo({
path: '/login',
query: {
reason: authReason,
redirect: to.fullPath === '/' ? undefined : to.fullPath
}
})
}
})