While the login/logout/middleware functionalities are working, I am facing an issue with controlling the token. I am attempting to store the JWT in Vuex store after logging in, but it is only being saved in a cookie and localStorage. As per the documentation, auth support in Vuex should be added automatically. I didn't specify tokenRequired
and tokenType
in the config, which according to the documentation, are required for a cookie-based flow (even though adding them did not make a difference).
nuxt.config.js
modules: [
'@nuxtjs/axios',
'@nuxtjs/auth'
],
axios: {
baseURL: 'https://api.example.com/'
},
router: {
middleware: ['auth']
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'login', method: 'post', propertyName: 'token' },
logout: { url: 'logout', method: 'post' },
user: false
}
}
},
redirect: {
login: '/login',
logout: '/',
callback: '/login',
home: '/'
}
},
login function
await this.$axios.post('authenticate', {
email: this.email,
password: this.password
}).then(response => {
if (response.success === 'true') {
this.$auth.setUserToken(response.token)
} else {
//alert invalid login
}
}).catch(error => {
//alert server error
});
After successful login, when I check $auth.$state, it shows
{ "user": {}, "loggedIn": true, "strategy": "local" }
I was expecting the token to also be stored in $auth
.
I came across a similar question on Stack Overflow, but the solution provided did not work for me since I have used user: false
.