E
E
Eugenue Cesarevich2021-03-26 21:39:41
JavaScript
Eugenue Cesarevich, 2021-03-26 21:39:41

How to implement "Remember me" feature with JWT?

My application already has JWT authorization. Now I want to make the function "Remember me". The bottom line is this: if the user has checked the box, then the next time the login will be performed automatically. And if he did not check the box, then after closing the tabs with the site, he will need to enter the login and password again.

The consideration is this: when the checkbox is checked, the token can be written to localStorage. It is more difficult with how to delete the token if there is no checkmark. If there is no checkmark, you can throw the token into sessionStorage, but this will not be very convenient - firstly, if the user opens the second tab, then he will have to log in again, and he will also have to pull the token from these two storages at once.

How would I best implement "Remember me" then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-03-26
@yarkov

Did you think about the second tab or did you try it? EMNIP sessionStorage is cleared if you close all site tabs, not for each individual storage.
And what's so hard about getting a token from two repositories?
They have the same API. We make a wrapper and pull its method, and under the hood we turn to the desired storage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question