How to implement nuxt middleware correctly for auth? #1532
Unanswered
anshumankomawar
asked this question in
Questions and Help
Replies: 1 comment
-
Theres getCurrentUser() that can be awaited. export default defineNuxtRouteMiddleware(async (to, from) => {
const user = await getCurrentUser()
if (!user) {
return navigateTo('/login')
}
})
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`export default defineNuxtRouteMiddleware(async (to, from) => {
const user = await getCurrentUser!();
});
`
this is my global middleware. I believe it works but there is an issue where getCurrentUser is initially null and then its value changes to a user after some time. The user is already logged in and I have enabled session store and persistance. This behavior only happens on safari I didnt have an issue while testing on chrome. Safari routes to the login page for a second and then redirects to the home page. I'm new to vue so would appreciate any help.
Beta Was this translation helpful? Give feedback.
All reactions