G
G
grabbee2020-11-21 14:45:55
Vue.js
grabbee, 2020-11-21 14:45:55

What to do if there is no authorization token?

To render a component, you need to get data from the server. And he gives them only by authorization token. And at the time of rendering, there is no token data yet. Getting data is tied to the component mounting hook. The token will be requested and installed after mounting this component. How to proceed in such a case?

That is, it would be good to wait for the token update and mount after it is updated. I just don't understand how to do it? You can set a timer, but this is some kind of crutch. There isn't just one component...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2020-11-21
@delphinpro

If there is no authorization token, then you need to direct the user to the login form and get it.
In the future, the token is stored, for example, in localstorage and is always available.
This token is sent to the server with each request (usually in the Authorization header), the server checks it each time. If the token is rotten, then the server returns 401, and the front, seeing such a response, erases the rotten token from itself and sends the user to the authorization form.
Something like this, if I understood you correctly.

A
Alexey Yarkov, 2020-11-21
@yarkov Vue.js

<component v-if="ЕСТЬ_ТОКЕН" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question