2.0.12 • Published 7 years ago
@javs/auth v2.0.12
Auth
Authentication module for Nuxt.js
Setup
- Add
@javs/auth
dependency using yarn or npm to your project - Add
@javs/auth
and@nuxtjs/axios
tomodules
section ofnuxt.config.js
{
modules: [
'@javs/auth',
// ...Axios module should be included AFTER @javs/auth
'@nuxtjs/axios',
],
auth: {
/* auth options */
}
}
Options
token
- Default: { useToken: false, tokenPrefix: null }
This option configure the setToken method of Axios module in the updateToken action.
Example:
{
token: {
useToken: true,
tokenPrefix: 'JWT'
}
}
Previous example generate this Authorization header in all future requests:
Authorization: JWT <token>
When the user logout or the token expire the header is remove for all future requests.
fetchUser
- Default: null
If the option exists it is used to obtain the user object in the api response in fetch action. If is null all response is passed to user object in the state.
fetchToken
- Default: null
This option is used in fetch action to obtain the token from api response. If is null, the module try to obtain the token from token or id_token property.
redirectLoggedIn
- Default: '/'
This option is used in no-auth middleware.
redirectNotLoggedIn
- Default: '/login'
This option is used in auth middleware.
License
Copyright (c) Nuxt Community