nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

rewriteRedirects:true not working with localScheme #1758

Closed StaymanHou closed 2 years ago

StaymanHou commented 2 years ago

Version

module: 5.0.0-1643791578.532b3d6 nuxt: 2.15.8

Nuxt configuration

//...
export default {
  //...
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/auth-next',
  ],

  auth: {
    redirect: {
      login: '/sign-in',
    },
    cookie: {
      options: {
        expires: 180,
        secure: true,
      }
    },
    rewriteRedirects: true,
    strategies: {
      local: {
        scheme: 'refresh',
        grantType: 'password',
        //...
      },
      google: {
        //...
      },
      facebook: {
        //...
      },
      customOpenID: {
        //...
      },
    }
  },
  ...
}

mode:

Reproduction

What is expected?

Setting rewriteRedirects to true would redirect the user back to the previous page with the auth middleware enabled after they successfully logged in regardless of the strategy being used.

What is actually happening?

When user logs in using the local strategy, it redirects the user to / instead of the previous page. However, all other strategies / schemes exhibits the expected redirect behavior.

Steps to reproduce

Additional information

I've tried debugging it a bit. Looks like all other schemes call the redirect function with the argument noRouter set to true. So it replaces the browser location directly, bypassing the entire routing mechanism. With the local scheme though, the redirect function gets invoked without the noRouter argument which then is set to false. Interestingly, the this.ctx.redirect function gets invoked with the correct to value, e.g. /restricted/page. However, instead of routing back to that page, it goes to / for some reason.

Checklist