nuxt-community / auth-module

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

Auth ignores nuxt.config.js settings for local login URL #363

Closed wonder95 closed 3 years ago

wonder95 commented 5 years ago

Version

v4.5.1

Reproduction link

http://no-link-sorry

Steps to reproduce

1) Install module 2) Configure nuxt.config.js to use `auth/login/' as login URL:

  auth: {
    strategies: {
      local: {
        endpoints: {
          login: {
            url: '/auth/login/',
            method: 'post',
            propertyName: 'key'
          },
          logout: {
            url: '/auth/logout/',
            method: 'post'
          }
        }
      }
    },
    redirect: {
      login: '/login',
      home: '/dashboard'
    },
    localStorage: {
      prefix: 'auth.'
    }
  },

The only place that I can find where this URL is set anywhere is in .nuxt/auth/plugin.js:

 // Register strategies

  // local
  $auth.registerStrategy('local', new scheme_003d9a64($auth, {"endpoints":{"login":{"url":"/auth/login/","method":"post","propertyName":"key"},"logout":{"url":"/auth/logout/","method":"post"},"user":{"url":"/api/auth/user","method":"get","propertyName":"user"}},"_name":"local"}))

What is expected ?

Configured login URL is called

What is actually happening?

Hardcoded usl 'auth/user` is called, resulting in 404 error

Additional comments?

I am using v 4.5.3, but form select list does not allow any value higher than 4.5.1

This bug report is available on Nuxt community (#c337)
pi0 commented 5 years ago

Hi. You also need to configure user endpoint. After page reloads nuxt needs to fetch user from API.

steklopod commented 5 years ago

Same problem. Deleting .nuxt folder does not help.

            local: {
                endpoints: {
                    login: {propertyName: false},
                    user: false,
                    logout: false
                }
            }

But got old value in plugins.js inside .nuxt folder:

    // local
    $auth.registerStrategy('local', new scheme_3e2123be($auth, {
        "endpoints": {
            "login": {
                "url": "/api/auth/login",  // <----- HERE is old value
                "method": "post",
                "propertyName": false
            }, "logout": false, "user": false
        }, "_name": "local"
    }))
dappiu commented 5 years ago

But got old value in plugins.js inside .nuxt folder:

    // local
    $auth.registerStrategy('local', new scheme_3e2123be($auth, {
        "endpoints": {
            "login": {
                "url": "/api/auth/login",  // <----- HERE is old value
                "method": "post",
                "propertyName": false
            }, "logout": false, "user": false
        }, "_name": "local"
    }))

@steklopod

/api/auth/login is the default value as you can see here https://github.com/nuxt-community/auth-module/blob/dev/lib/module/defaults.js So that is not an "old" value, just the value you get because you're not setting the property to another value.

change login: {propertyName: false}, to login: { propertyName: false, url: '/something/else' }, and you will see the difference.

brooks693 commented 5 years ago

Same issue for me.

Whatever I set url to is ignored and goes to default.

I've tried renaming the strategy to something other than local and just get a different error now.

I have an old project that uses the same config that works (just a different baseURL for axios).

I've just updated the defaults in the module for now to get it working but not ideal.

brooks693 commented 5 years ago

Fixed the problem!

My nuxt.config file had 2 auth objects. One that I had filled in correctly, and a second that was blank..

Just deleted the blank one and all works as expected.

:-/