J
J
Jedi2020-01-05 14:31:57
OAuth
Jedi, 2020-01-05 14:31:57

Question about the implementation of authorization on React + Redux. What data should we store in localStorage and state redux?

Hey!
Upon successful authentication, we get an access token. We store it in localStorage.
In my case, I also send expires in , save to localStorage. When loading the application, I check if the token has expired. It's easier. Since I'm using LARAVEL with PASSPORT (OAuth) on the back end , I don't quite understand all the OAuth charms yet.
REDUX
In the tutorials, people dispatch from a JWT (We don't have a JWT) into a user object with user data. Question.. why? Is it really necessary?
Do I need to store user data in localStorage? I don't see any logical sense in this.
Could you please tell us what data we should store with the client, what dispath and how it should look like on the reducer (reducer) in conjunction with LARAVEL PASSPORT (OAuth) , React js and REDUX ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Also_known_as, 2020-01-06
@PHPjedi

Redux state is used to control the state of the SPA application, storing personal data in the redux state is not best practices, session storage is used for this or less often local storage, although the choice in favor of the latter also has limitations, it is best to keep the token in session storage, it is best suited , since the SPA application on the backend uses rest api or graph ql, the token must be regularly transmitted in the body of any request to the server, and it is desirable to implement a check on the time of its validity and its regular updating on the frontend side.
As for "dispatch from jwt" - how is it and what is it all about? All processes related to the generation of a token occur on the back-end, only json and a string in the storage are output, this is all that should be on the front.
A reducer is a method for updating an application's state. Here we can execute asynchronous code, requests to the server, and throw the received data necessary for the application to work in the state. In the reducer, we address the received token to the server and save the date in the session or local storage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question