What if there is no authorization token?
To render the component, you need to get data from the server. And he gives them only by the authorization token. And at the time of rendering the data, there is no token yet. Data retrieval is tied to the component mount hook. The token will be requested and installed after this component is mounted. How to proceed in this case?
That is, it would be good to wait for the token update and mount after its update. Just don't understand how to do it? You can set a timer, but it's some kind of crutch. And there is more than one such component ...Vue.js Rose Santiago, Oct 7, 2020
If there is no authorization token, then you need to send the user to the login form and get it.
Further, the token is stored, for example, in localstorage and is always available.
This token is sent to the server with every request (usually in the Autorization header), the server checks it every time. If the token is rotten, the server returns 401, and the front, seeing such a response, erases the rotten token and sends the user to the authorization form.
Something like this, if I understood you correctly.Anonymous
& lt; component v-if = "THERE IS_TOKEN" / & gt;Anonymous
To place the code, please use CodePen or similar tool. Thanks you!