Auth-module: 'redirect callback' ignores 'router base'

Created on 3 Dec 2018  路  11Comments  路  Source: nuxt-community/auth-module

Version

v4.5.1

Reproduction link

#sorry/for/no/reproduction/link

Steps to reproduce

1.
in nuxt.config.js

router: {
  base: "/some_custom_base_path",
}
auth: {
  ...
  redirect: {
    login: '/login',
    logout: '/login',
    callback: '/some_callback_path',
    home: '/'
  }
}

2.
try login facebook

What is expected ?

Expected redirect to http://mydomain.com/some_custom_base_path/some_callback_path

What is actually happening?

Happening redirect to http://mydomain.com/some_callback_path

Additional comments?

Other redirects working correctly.

This bug report is available on Nuxt community (#c241)
bug

Most helpful comment

Nevermind, doing what I proposed causes issues with callback routes not matching correctly.

All 11 comments

Any ideas on this issue so far ?

I'm interested in this one.

Note that you can work around this by making each of the callback values include your base url. So IMHO I would create a const in the config file for the base url and prepend it to each callback.

Auth-module should take the base url into account though, since that's baked into nuxt.

Nevermind, doing what I proposed causes issues with callback routes not matching correctly.

Hi, Just want to add few notes about the Fix I proposed .

  1. I tried using document.baseURI for this purpose but it will not work because
    a. it will break if router.base is not set. In that case, we will get document.location.href as baseurl which is wrong.
    b. This fix can not work in server if we implement in this way
    c. We have to process document.baseURI whenever we use it. That is , we need to use document.baseURI.slice(0,-1) whenever we need to use this value to remove trailing slash.

@harish2704 Did you see my PR - #489? I believe my PR covers all of the bases. Let me know if you see something that doesn't work and put a comment on the PR.

Hi @NickBolles ,

I had checked this PR before I start implementing my own solution.

489 has many commits and too many changes and, I was facing difficulty to understand the PR as whole .( It can be due to my incapability, but this is what happened. )

That is why tried to solve this issue by introducing minimum changes to the system.
The changes I proposed has only 4 lines of changes and , I believe it is easily readable and understandable

@harish2704 No doubt that your fix is concise. But i believe it misses multiple scenarios. I will add a few comments to your PR.

@NickBolles @harish2704 do any of you have a workaround, our you're just using your respective forks?

Just include your router base in your auth config urls. So if base = /foo login = /foo/login

Hmmm...

async _handleCallback (uri) {
    // Handle callback only for specified route
    if (this.$auth.options.redirect && this.$auth.ctx.route.path !== this.$auth.options.redirect.callback) {

ctx.route.path is relative, while redirect.callback is absolute, so the callback code doesn't work...I'm not seeing how your solution solves this?

@blocka your right. Im just using my branch. You can try it out with npm I NickBolles/auth-module#njb/use-router-base and add comments to #489

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javialon26 picture javialon26  路  3Comments

sebmor picture sebmor  路  3Comments

weijinnx picture weijinnx  路  3Comments

manniL picture manniL  路  4Comments

aaronhuisinga picture aaronhuisinga  路  3Comments