Answer the question
In order to leave comments, you need to log in
How to work with sessions in reactjs?
function managerLogin(){
... //Запрос для входа менеджера
cookie.set('MANAGERSESSID', response.MANAGERSESSID);
...
}
function userLogin(){
... //Запрос для входа пользователя
cookie.set('LKSESSID', response.LKSESSID);
...
}
Answer the question
In order to leave comments, you need to log in
Your front-end worker should be advised to first study how this is done and then fence the garden.
but judging by the fact that you figure it out instead of him, everything suits him and you don’t.
Of course, no one does this, there are concepts of authentication and authorization, the session is established after authentication (the user confirms that he is he) and then this user logs in with some rights and authorization attributes are put into the session in some suitable way, in the simplest case - user role (admin/user). The front can request these attributes from the back in a separate request or receive them in a response to /login.
It is not very clear what "user login request" and "manager login request" mean -
you are supposed that the user will click on different buttons "log in as manager" and "log in as user" or what?
Normally so:
The button for login - one.
authentication request - one.
the server responds with an error or a success response. The session itself is set by a cookie, this cookie should be httpOnly and is not accessible from the js code. It works exclusively with the backend and as it wants.
From the server's response (in the body) or by making a separate request (such as /currentUser), Appa understands what kind of user it is - a manager or a regular one, and saves it somewhere to itself. In the case of react, this is most likely a stor. It is possible in localStorage to read from there immediately upon reboot.
Then the app just looks to the store at the right moments to understand what to show to the user what not.
The backend resolves all rights to requests based on a session cookie that comes with each request automatically. That is, the front does not concern the session as such at all - its job is to call login / logout, get information about the current user from the back and process 401 correctly.
You can do more complex options - without cookies, with some kind of tokens and so on, but most likely it is still too early for your frontend.
There is no need to separate sessions on the client.
The role is usually defined using the corresponding field in the user data object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question