1

I'm using nuxtjs/auth library to do the authentication flow with Local Scheme. After login I can navigate page by page without any problem, however If I refresh the page, I will always be redirected to the login page.

I've add such to my express middleware to debugging.

app.use(function(req,res,next)
{
    console.log('#####')
    console.log(req.sessionID);
    console.log(req.headers);
    console.log(req.session.user ? 'true' : 'false');
    console.log('##############')
    next();
});

I found that every time I refresh there will be two web service call to the /user endpoint, with following output:

1.

#####
77IS0qWDOCp2GVX7s2744Vl7PkTPo00i
{
  'user-agent': 'axios/0.20.0',
  host: 'localhost:3000',
  connection: 'close'
}
false
##############
#####
6xHIHznvglt0PPb51ll5__dzhWjq6u_j
{
  host: 'localhost:3000',
  connection: 'keep-alive',
  accept: 'application/json, text/plain, */*',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
    'AppleWebKit/537.36 (KHTML, like Gecko) ' +
    'Chrome/85.0.4183.102 Safari/537.36',
  'sec-fetch-site': 'same-origin',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  referer: 'http://localhost:3000/',
  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'en-US,en;q=0.9,zh-TW;q=0.8,zh;q=0.7',
  cookie: 'auth.strategy=local; auth._token.local=false; ' +
    'auth._refresh_token.local=false; ' +
    'connect.sid=s%3A6xHIHznvglt0PPb51ll5__dzhWjq6u_j.6sPDezrnEw50IaBhYhhN%2FUCH5KUCB8fYQLoI1%2B3TAxA; ' +
    'auth.redirect=%2Fsecret',
  'if-none-match': 'W/"b5-V50YCe0fwKnv7GWmdocLX3+We+E"'
}
true
##############

It seems that the mysterious first call submitted without any header and therefore cannot retrieve the session, then the front end determined it as not login.

Version:

"@nuxtjs/auth": "4.9.1",
"@nuxtjs/axios": "5.12.2",
nathan1658
  • 175
  • 1
  • 14
  • 1
    it looks like the token is not stored properly in your app, mind you sharing nuxt/auth setup – MAS Oct 07 '20 at 12:38
  • I have the same question! https://stackoverflow.com/questions/64444811/nuxtjs-auth-module-not-working-in-the-middleware – Fabio Magarelli Oct 20 '20 at 12:31

0 Answers0