How to set an access_token in header and keep in in current state after refreshing?
Closed this issue · 1 comments
zablik commented
In order to access an API a need to add the current JWT token to API client's default headers.
oidcStore module has an API to get access_token
, it is oidcAccessToken
getter.
So my question is how can I call this oidcAccessToken
getter inside userLoaded
event callback?
Maybe there is a better place to set this header?
Is there an event to handle access_token change?
Thanks!
// In my `store/index.js`
export default createStore({
state: {},
mutations: {},
actions: {},
modules: {
oidcStore: vuexOidcCreateStoreModule(
oidcSettings,
{
namespaced: true
},
{
userLoaded(user) {
// set access_token
axios.defaults.headers.common['Auth-Token'] = ... ;
},
userUnloaded() {
// delete access_token
axios.defaults.headers.common['Auth-Token'] = null;
}
}
)
}
});
perarnborg commented
Duplicate of #153