S
S
someberry2017-04-06 20:40:08
JavaScript
someberry, 2017-04-06 20:40:08

How to control redux+react authorization?

Good afternoon!
There is an enterprise solution with a heavy guy and a crooked REST API.
I decided to write a lightweight front for basic needs (my/colleagues), I know js a bit, read smart books about react/redux.
It is necessary to control the presence of an authorization session for the user.
Input data:
1) Basic Auth
2) Cookies are not given without "expire", and until the server drops the session for inactivity (30-60 minutes, depends on the server settings)
3) When making a request, when the session is turned off - a normal http response about that you need to log in again.
I need to understand how to fit into the concept of react and redux a check to see if the session has ended. Up to this point, if you worked with api, then long cookies or some tokens were given.
Well, I see two possible solutions:
1) A function that will send the easiest request to the server and check authorization, and then call the main request.
2) Create a common template function for all types of requests and check the response in it if 401 is a request with authorization and call yourself again with the previous parameters.
This is so far, thoughts out loud. Please tell me how best to act in this case and how to break it down into actions / reducers / etc.
You don't have to write code for me :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2017-04-06
@vshvydky

I am for the exchange through an authorized socket io, it will break so it will break. New connection via token.

I
Ilya, 2017-04-06
@FireGM

make a middleware for redux, which will make requests to the backend, check the response, and if the backend requires authorization, change the page through redux, ask for authorization.
Here is an example
api client
middleware
application

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question