auth-next not redirecting after login and can't access protect page even if token is stored
See original GitHub issueVersion
“@nuxtjs/auth-next”: “5.0.0-1608219886.ec0152d”, “nuxt”: “^2.14.7”,
Nuxt configuration
- universal
Nuxt configuration
auth: {
localStorage: false,
strategies: {
local: {
endpoints: {
refresh: {
url: '/refresh-token',
method: 'get',
propertyName: 'jwt',
},
login: { url: 'login', method: 'post', propertyName: 'token' },
user: { url: 'users/profile', method: 'get', propertyName: false },
logout: false,
},
user: {
property: 'user',
autoFetch: true,
},
token: {
property: 'token',
type: 'Bearer',
required: true,
},
},
},
redirect: {
login: '/entrar',
logout: '/entrar',
home: '/templates',
},
},
What is expected?
To redirect to /templates page after login
What is actually happening?
It stores all cookies auth._token.local
, auth._token_expiration.local
and auth.strategy
, but it’s not redirecting to /template (home)
And even more, if i try to enter a page that needs auth, it redirects me to login page
I also tried to store in localstorage, but still doesn’t work
Also after login request, it calls users request just after success
iat is 1 hour
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Nuxt auth not redirecting after logout - Stack Overflow
I have been through the documentation multiple times, but still can't figure out why I don't get redirected to login/ when I click...
Read more >Frequently Asked Questions - NextAuth.js
Advantages of using a JWT as a session token include that they do not require a database to store sessions, this can be...
Read more >Sign users in to your SPA using the redirect model
Require authentication on protected routes. Get authenticated user info. Make an HTTP call with the access token. Check the integration by signing in...
Read more >Building an authentication API with NextAuth.js
After submitting the form, we should be redirected to a success page and receive an email with a verification token if that's the...
Read more >Authenticated server-side rendering with Next.js and Firebase
sign in users (duh); generate ID tokens; store those ID tokens as a cookie ... redirect unauthenticated users to a login page from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@CavalcanteLeo Thank you! 😃
I’ll add “improve error handling” to to-do list
After a video call with @JoaoPedroAS51 we figured out the problem was the way I set the user config in nuxt.config
But if the nuxt-auth have thrown me an error, would be much easier to figure out. My suggestion is to throw erros back to all requests, then we can figure out much faster.
My error was because the property had to be set as false, and when nuxt-auth made the request, it cound’t parse and the state
loggedIn
was always false.also nuxt-auth should handle when it occurs, i couldn’t parse profile API, my states was loggedIn false but all cookies were set
I really appreciate your time and help @JoaoPedroAS51