initial commit
This commit is contained in:
10
app/middleware/auth.global.js
Normal file
10
app/middleware/auth.global.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const LOGIN_PATH = '/login'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
if (to.path === LOGIN_PATH) return
|
||||
const { user, refresh } = useUser()
|
||||
await refresh()
|
||||
if (user.value) return
|
||||
const redirect = to.fullPath.startsWith('/') ? to.fullPath : `/${to.fullPath}`
|
||||
return navigateTo({ path: LOGIN_PATH, query: { redirect } }, { replace: true })
|
||||
})
|
||||
Reference in New Issue
Block a user