Follow the steps in the small detailed guide...
Example failed request because bad token: http://prntscr.com/kxf48b
Result in the local storage: http://prntscr.com/kxf4i6
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.
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.
Also, just as a side note, the login redirect is not working either... Login works tho.
See #134 for a workaround.
Any fixes?
I am also running into this issue. Any update?
Move your plugs' declaration into auth
module.exports = {
plugins: [
<some plugins without auth>
],
...
auth: {
redirect: {
...
},
strategies: {
...
},
...
plugins: [
'~/plugins/your-plugin-with-auth.js'
]
},
@themondays - Thank you. That does indeed work - missed this in the documentation.
I think this can be closed as resolved @pi0
Should definitely be more clear in the documentation
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.
@themondays Thanks! Been wasting a couple of hours on this one... :(
Move your plugs' declaration into
authmodule.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.
For some reason you need to use ~ and @ syntax is not working like nuxt-config.js plugins.
Most helpful comment
Move your plugs' declaration into
auth