Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$auth not defined in plugin & resetOnError option is ignored... #245

Closed
ConsoleTVs opened this issue Sep 22, 2018 · 13 comments
Closed

$auth not defined in plugin & resetOnError option is ignored... #245

ConsoleTVs opened this issue Sep 22, 2018 · 13 comments
Labels

Comments

@ConsoleTVs
Copy link

Version

v4.5.1

Reproduction link

http://prntscr.com/kxf2s5

Steps to reproduce

Follow the steps in the small detailed guide...

What is expected ?

  • To have the $auth inside the plugin to use .onError
  • To log out the user if the request fails (resetOnError is true)

What is actually happening?

  • $auth is undefined
  • The user is not logged out, so I must find alternatives like using $auth in the plugin but I'm unable to...

Example failed request because bad token: http://prntscr.com/kxf48b
Result in the local storage: http://prntscr.com/kxf4i6

Additional comments?

nuxt.config.js:

    auth: {
        // See https://auth.nuxtjs.org/getting-starterd/options
        redirect: {
            login: '/',
            logout: '/',
            user: '/dashboard'
        },
        strategies: {
            local: {
                endpoints: {
                    login: { url: '/login', method: 'post', propertyName: 'token' },
                    logout: { url: '/logout', method: 'post' },
                    user: { url: '/user', method: 'get', propertyName: 'user' }
                },
            }
        },
        resetOnError: true
    },

Also, just as a side note, the login redirect is not working either... Login works tho.

This bug report is available on Nuxt community (#c203)
@ghost ghost added the cmty:bug-report label Sep 22, 2018
@shawnlauzon
Copy link

I'm hitting the same problem: my token to the server is expired, and so I want to logout and force getting a new token. Unfortunately resetOnError is not resetting the token, and my plugin (which is defined in the auth/plugins property as defined here rather than at the top level sees this.$auth is undefined.

@shawnlauzon
Copy link

Also, just as a side note, the login redirect is not working either... Login works tho.

See #134 for a workaround.

@nuxt-community nuxt-community deleted a comment from ConsoleTVs Nov 10, 2018
@killlerr
Copy link

Any fixes?

@nuxt-community nuxt-community deleted a comment from ConsoleTVs Mar 2, 2019
@nicbavetta
Copy link

I am also running into this issue. Any update?

@themondays
Copy link

themondays commented Apr 3, 2019

Move your plugs' declaration into auth

module.exports = {
    plugins: [
        <some plugins without auth>
    ],
    ...
    auth: {
        redirect: {
        ...
        },
        strategies: {
        ...
        },
        ...
        plugins: [
             '~/plugins/your-plugin-with-auth.js'
        ]
    },

@nicbavetta
Copy link

@themondays - Thank you. That does indeed work - missed this in the documentation.

@gkkirilov
Copy link

I think this can be closed as resolved @pi0

@simplenotezy
Copy link

Should definitely be more clear in the documentation

@simplenotezy
Copy link

The problem with this method is that inject does not work inside a auth-plugin; so you'll need to include your plugin both places.

@emielmolenaar
Copy link

@themondays Thanks! Been wasting a couple of hours on this one... :(

@amirakbulut
Copy link

amirakbulut commented Jun 2, 2020

Move your plugs' declaration into auth

module.exports = {
    plugins: [
        <some plugins without auth>
    ],
    ...
    auth: {
        redirect: {
        ...
        },
        strategies: {
        ...
        },
        ...
        plugins: [
             '~/plugins/your-plugin-with-auth.js'
        ]
    },

How does this solve making resetOnError: true work? Not really getting it.

@kaangokdemir
Copy link

For some reason you need to use ~ and @ syntax is not working like nuxt-config.js plugins.

@bmulholland
Copy link
Contributor

Closing as stale for now. Please re-open a new issue if this is still present on nuxt-auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests