This is something more likely as conception question. I am doing the Front-End of website and there is already created Back-end from another person. One of his endpoints is "Login endpoint" which sends me in reply several stuff:
- Token (JWT)
- UserId
- Name
- Address
- Company
(and some others)
I receive all of them directly after login as response. So I am wondering which is the best way to save them? As we can assume it will not be a problem to save everything except Token in localStorage or in cookie with js-cookies package but how to store a token? It is unsafe to be stored both in local/session storage and in cookie. Currently I have Auth context which stores all of this:
import React from "react";
export default React.createContext({
token: null,
userId: null,
address: null,
firstName: null,
lastName: null,
email: null,
company: null,
subscription: null,
login: (token, guid) => {},
logout: () => {},
});
After login I pass it in
<AuthApi.Provider
value={{
token,
guid,
login,
logout,
address,
firstName,
lastName,
email,
company,
subscription,
}}
>
In the App.js so they are accessible from all components inside the project with useContext.
As you know, when browser is refreshed we lost all the values. So basically here I don't store the values and Token also in cookie or local/session storage but I loose it after refresh. What is the best solution here if I cannot make changes in the back-end?