question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirection to login page on hard refresh even if Logged In already (laravel/sanctum)

See original GitHub issue

Version

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,

  1. http://localhost:8000/sanctum/csrf-cookie —> Ok
  2. http://localhost:8000/login —> Ok
  3. http://localhost:8000/api/user---> Ok
  4. 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bmulhollandcommented, Dec 11, 2020

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.

0reactions
asadullakkhcommented, Sep 8, 2022

I have tried all of them, but still not working, I have been trying to solve this problem for three days(

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - @nuxtjs/auth Why refresh page always redirect to login
I'm using Nuxt with Laravel Sanctum and the thing that solved the problem for me was an issue with the ...
Read more >
Sanctum with Socialite and SPA - Laracasts
I'm having hard times trying to get Socialite and Sanctum running on SPA webiste... i would like to use SPA authentication as recommended...
Read more >
HTTP Redirects - The PHP Framework For Web Artisans
The simplest method is to use the global redirect helper: ... to redirect the user to their previous location, such as when a...
Read more >
Getting started with Laravel Fortify and Sanctum - YouTube
In this 19 minute video, I'll show you how to install and use the Fortify and Sanctum authentication packages in example Laravel ......
Read more >
Laravel Authentication: A Laravel Passport Tutorial - Toptal
If we start the application server—i.e., run php artisan serve —and then try to send a GET request to the route /api/user ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found