M
M
Marshall_s2021-08-20 10:23:19
User identification
Marshall_s, 2021-08-20 10:23:19

Authorization on React?

Hello everyone,
please tell me how best to do authorization on the front, what is now:
- the user enters data in the authorization form, sends
- if successful, a session for this user is opened on the back for 168 hours and the back returns the user ID and token

How better store "authorized" state on the front? I went in the direction of localStorage, I save the id and the token, when I open some pages I check the localStorage if the given user is authorized, but how to clear the localStorage after 168 hours?

Or is there another way, more correct and convenient than localStorage?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-08-20
@Marshall_s

how to clear localStorage after 168 hours?
Together with the token, you need to store its decay time and, when reading and using it, check if it has expired. Well, the backend, of course, should respond with an error if the token is rotten - in this case, also clean the old value.
Or is there another way, more correct and convenient than localStorage?
There are other client storages, but more supported than LS - no.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question