I'm working on a Vuejs app and the backend is returning only a token when a user login succefully.
What I wanna do, is to store somewhere the role of the user to use it in beforeEnter() in the router.
When the user logs in, a request fetchs the user informations (with the role). But when I refresh the page or when I change the route, I lose the states.
Si I was going to put the user infos in the LocalStage but I'm pretty sure that it's not safe at all because I can edit the role in Application (in Chrome)..
I need to have the role available all the time in the router but I don't know how except with the localstorage
Any solutions?
EDIT: Because I got only a token as response from the backend. Is it good to directly call another request to fetch the userdata(including role) ?
Like so:
export function loginUser ({ commit }, payload) {
return new Promise(resolve => {
LoginService.login(payload)
.then(data => {
console.log('enter')
console.log(data)
let tkn = data.access_token
Cookies.set('tkn', tkn.toString())
Cookies.set('cntd', 'true')
---> UserService.getB2cUserProfile()
.then(data => {
commit('LOGIN_USER', data)
// will commit the data here to change the userInfos state
resolve(data)
})
})
.catch(err => {
console.log(err)
})
})
}