Files
chatgpt-ui/middleware/auth.ts
2023-04-03 18:19:39 +08:00

18 lines
474 B
TypeScript

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)
}
})
}
}
})