Clarify auth states
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user