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.

auth-next not redirecting after login and can't access protect page even if token is stored

See original GitHub issue

Version

@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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
JoaoPedroAS51commented, Dec 18, 2020

@CavalcanteLeo Thank you! 😃

I’ll add “improve error handling” to to-do list

1reaction
CavalcanteLeocommented, Dec 18, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

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