Currently, _request function in auth.class.js uses Object.assign to merge this.options.endpoints[name] and endpoint.
const opts = Object.assign({}, this.options.endpoints[name], endpoint)
In my use case, I need to add some headers and a propertyName to my request.
Adding these values to nuxt.config.js doesn't work.
Adding them in this.$auth.login({...}) works.
I think that it might be because Object.assign uses shallow merge. I suggest swapping it for deep merge.
@JesusCrow
endpoints: {
login: { url: '/api/auth/login', method: 'post', propertyName: 'token', headers: { 'Content-Type': 'application/x-www-form-urlencoded' } },
logout: { url: '/api/auth/logout', method: 'post' },
user: { url: '/api/auth/user', method: 'get', propertyName: 'user' }
},
I just tried this on the demo example and it worked.
I think there is no need for shallow merging, but if you feel limited by this, feel free to-reopen.
Maybe I'm doing something wrong than.
auth: {
fetchUserOnLogin: false,
endpoints: {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic XXXXXXXXXXXX'
},
login: 'api/oauth2/token',
method: 'post',
propertyName: 'access_token'
}
},
with
this.$auth.login({
data: {
username: 'username',
password: 'password',
grant_type: 'password'
}
})
fails, while this
this.$auth.login({
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic XXXXXXXXXXXXX'
},
data: {
username: 'username',
password: 'password',
grant_type: 'password'
},
propertyName: 'access_token'
})
works
@JesusCrow You set headers in the endpoints, we don't support assigning a headers globally, you can only set headers in a specific endpoint.
Oh......
Sorry, I thought I was writing inside login, and not endpoints! Such a foolish mistake, I'm going to do a seppuku with a :dango:
Thanks!
Most helpful comment
@JesusCrow You set headers in the
endpoints, we don't support assigning aheadersglobally, you can only setheadersin a specific endpoint.