Working on a project using the Nuxt auth-module. The Login API response is structured like this:
data:{
data:{
user:{
bio: null,
createdAt: "2021-06-29T12:28:42.442Z",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1cfc0ccc4e1c8cfc7ce8fc2ce">[email protected]</a>",
id: 1,
image: null,
token: "token",
updatedAt: "2021-06-29T12:28:42.447Z",
username: "name"
}
}
}
nuxtconfig:
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'users/login', method: 'post', propertyName: 'data.user.token' },
user: { url: 'me', method: 'get', propertyName: 'data' },
logout: false
}
}
}
},
Having trouble saving the token in the app. Any suggestions?
After some research, I came across a solution:
auth: {
strategies: {
local: {
token: {
property: 'user.token', // /user endpoint API returns user object
type: 'Token' // if your token type is not Bearer
},
user: {
user: 'user'
},
endpoints: {
login: { url: '/users/login', method: 'post' },
user: { url: '/user', method: 'get' },
logout: false
}
}
}
},