Answer the question
In order to leave comments, you need to log in
How to store an authorized user on the frontend?
Good afternoon!
A question of understanding, I'm struggling with the logic of how to do it right,
and how others do it right :)
I have a node.js server that generates a JWT token and passes it to the frontend in cookies with the httpOnly flag (I have vue).
for example like this:
res.cookie('AuthToken', authToken, { httpOnly: true, secure: true })
req.cookies['AuthToken']
"AuthToken_2"
res.cookie('AuthToken_2', JSON.stringify(user), { httpOnly: false})
AuthToken_2
? computed: {
reversedMessage: function () {
return this.$store.state.count
}
},
router.beforeEach( async (to, from, next) => {
store.getters.doneTodos
next()
})
getters: {
doneTodos (state) {
return state.count = Cookies.get('AuthToken_2')
}
}
Answer the question
In order to leave comments, you need to log in
It is logical that when sending a token, you can add another jison in which there will be user Settings, save them to the store and then take them from them. Or, after receiving the token, you redirect to the user profile, get the information there and save it, and optionally redirect to the page from which the login was made.
a separate route to get the user.
those. authentication, then data request. data in localStorage. do not forget that this data cannot be particularly trusted later, and during operations it is necessary to check their validity on the back.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question