The issue of implementation of authorization on React + Redux. What data should we store in localStorage and state redux?

Hi!

If successful authentication we get the token (access token). We store it in localStorage.
In my case, I also sent in the expires, save in localStorage. When you download the app, they check whether expired token. It's easier. Since on the backend I'm using LARAVEL with PASSPORT (OAuth), I don't quite understand all the charm of OAuth.

REDUX
In the tutorials people dispatched from JWT (JWT Have not) in user object's user data. Question.. why? Do you need it?

Do I need to store custom data in localStorage? I see no logical sense.

Please tell us what data we need to keep the client what dispath'it and how to look for the reducer (gearbox) in conjunction LARAVEL PASSPORT (OAuth), React js and REDUX?
April 4th 20 at 00:50
1 answer
April 4th 20 at 00:52
Solution
Redux state is used to monitor the status of SPA applications, to store personal data in redox state is not best practices, it uses session storage or local storage less, although the choice in favor of the latter, too, has limitations, the token is best to keep in the session store, it is best suited, as in the SPA application on the backend using a rest api or graph ql, the token must be regularly transmitted to the body of any access to the server and preferably on the side of the front end to implement the test time of its action and its regular update.

As for the "dispatchit from jwt" - in what way and what is it all about? All processes associated with the generation of the token occur on the backend only outputs a json string in the repository, that's all that should be on the front.

Reducer is a method of updating state of the application. Here we can execute asynchronous code requests to the server and the obtained data is necessary for the application to throw in state. In redusere connects to the server the token received and the date stored in the session or local storage.
About reducer what is doubtful, given that reduser is a pure function - ashlynn commented on April 4th 20 at 00:55
@ashlynn, Oh Yes, the async is happening in the actions, but the essence does not change then the updated state in reducer is the store operation in General - adela_Cruickshank commented on April 4th 20 at 00:58

Find more questions by tags OAuthReact