support ssr

This commit is contained in:
Rafi
2023-04-03 18:19:39 +08:00
parent deb627a9ab
commit 5b9d52b177
10 changed files with 975 additions and 1223 deletions

17
middleware/auth.ts Normal file
View 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)
}
})
}
}
})