Redirection to login page on hard refresh even if Logged In already (laravel/sanctum)
See original GitHub issueVersion
module: 5.0.0-1607600955.506103a nuxt: 2.14.11
Nuxt configuration
[mode] univeral
- universal
- spa
Nuxt configuration
Reproduction
for backend I installed Laravel 8 + laravel/sanctum to handle the authentication. for frontend I installed Nuxtjs along with @nuxtjs/auth-next package and everything worked fine,
- http://localhost:8000/sanctum/csrf-cookie —> Ok
- http://localhost:8000/login —> Ok
- http://localhost:8000/api/user---> Ok
- redirected to /dashboard with
middleware : 'auth'
except when I hard refresh on all pages with middleware “auth” it redirects to login page. here is what I have learnt so far :
this file "node_modules/@nuxtjs/auth-next/dist/core/middleware.js"
is responsible for “auth” middleware, when I hard refresh on a page with middleware “auth” attached , in line 16 if (ctx.$auth.$state.loggedIn)
I added the console.log to print the content of ctx.$auth.$state.loggedIn
to see if it is true or not but unfortunately it was undefined , then added store/index.js to see if it could help , the only change I saw was that I was getting default value “false” this time and still detected that I was not loggedIn and redirect me to login page, when page is reloaded now $auth.loggedIn is true and I have the user object but on the Nodejs server side no difference, I have read a lot of pages and people are having the same problem,
What is expected?
to simple reload current route without redirecting to login page when loggedIn = true
What is actually happening?
when hard refresh redirect to login page even if I am logged In
Steps to reproduce
described all in above
Additional information
Checklist
- I have tested with the latest Nuxt version and the issue still occurs
- I have tested with the latest module version and the issue still occurs
- I have searched the issue tracker and this issue hasn’t been reported yet
Steps to reproduce
install nuxtjs install @nuxtjs/auth-next add configuration as I mentioned in above paragraph
this.$auth.loginWith('laravelSanctum', {
data: {
email : 'test@test.com',
password : 'password'
})
.then(res => {
this.$router.push('/dashboard');
})
.catch(err => {
console.log(err);
});
What is expected?
Stay on current page and just reload the page without redirecting to login page !!!
You have done a great job handling all the authentication in this package and If you fix this problem , we really appreciate it
Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
You’ll get the best time-to-resolution by doing your own debugging and/or working toward a minimal repro. We’re all busy with our own problems and aren’t able to help you in real time. If you nail down a specific issue with this library then it really speeds up how quickly we can fix it.
I have tried all of them, but still not working, I have been trying to solve this problem for three days(