Nuxt Auth Module - How to create Success Redirect

Viewed 4622

I'm trying to a page in my nuxt app, where the user is on a dynamic route. On this route he has the possibility to log in and should then be redirected to exactly the same route. For the authentification I want to use the auth0 strategy.

I thought the following line would work:

this.$auth.loginWith('auth0')                 
  .then(() => {                               
    this.$router.push("/the-same-route-im-already-on");  
  })  

But apperently I'm only redirected to my home route "/loggedin". And changing the home redirect in my nuxt.config to false, redirects me to my callback-route "/login"

Right now my nuxt.config.js looks like this:

auth: {  
    auth0: {
     ...
    },
    redirect: {
      login: '/',
      logout: '/',
      callback: '/login',
      home: '/loggedin',
    }
}
1 Answers

I think the default behavior of rewriteRedirect in nuxt Auth Module, should redirect you to the original guarded route.

rewriteRedirect

If this is not working maybe you could redirect the user to login route manually passing a query like this

this.$router.push({ path: '/login', redirect: 'actualRoute' });

And then check in your login page if redirect is setted and then after login you call $router passing the value of redirect.

I don't know if this will help you, so let me know.

Related