I am utilizing the NuxtJs auth module to manage my authorization within the application state. I have created an express API specifically for this purpose, and it functions correctly.
Below is the configuration included in my nuxt.config.js file:
axios: {
baseURL: 'http://localhost:4000/api'
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: '/users/login', method: 'post', propertyName: 'data.token' },
user: { url: '/users/me', method: 'get', propertyName: 'data' },
},
}
}
},
Within my login component, I trigger the login route using the following code snippet:
const { data } = await this.$auth.loginWith('local', {
data: this.login
})
The first call to the /api/users/login route is successful (200), but the subsequent call to /api/users/me results in an error message:
xhr.js:178 GET http://localhost:4000/api/users/me 401 (Unauthorized)
When testing the API endpoint in Postman, I retrieve the user data successfully using the following setup:
> Get - localhost:4000/api/users/me
>
> Authorization:
>
> Type: Bearer Token Token: xxxx
Despite the fact that the Nuxt auth module defaults to 'Bearer' type, in my case, it does not function accordingly. While the user login process works as expected, retrieving user data through the second route encounters authorization issues. It's worth noting that the API operates independently from NuxtJS, implemented in a separate project using Express.