support ssr
This commit is contained in:
17
middleware/auth.ts
Normal file
17
middleware/auth.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const user = useUser()
|
||||
const signInPath = '/account/signin'
|
||||
if (!user.value && to.path !== signInPath) {
|
||||
const error = await fetchUser()
|
||||
console.log(error)
|
||||
if (error) {
|
||||
return navigateTo({
|
||||
path: signInPath,
|
||||
query: {
|
||||
callback: encodeURIComponent(to.fullPath)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user