I'm facing an issue where I can't save the localStorage across redirects. Here is my code:
// Call newSitelogin(). Set response(credentials) to localStorage. Redirect to new url.
newSitelogin({ uuid, password })
.then(() => {
window.open(process.env.NEW_SITE_URL); // This line clears localStorage.
})
.catch(() => replaceRouteWith('/'));
Endpoint to call the api and set the response in localStorage
newSitelogin(payload) {
return yield put.resolve({
[RSAA]: {
endpoint: `/auth/hubv3-login`,
method: 'POST',
body: JSON.stringify(payload),
types: [
ACTION.LOGIN_REQUEST_PERFORM,
{
type: ACTION.LOGIN_REQUEST_SUCCESS,
payload: (action, state, res) =>
getJSON(res).then(json => localStorage.setItem('credentials', JSON.stringify(json))), // setting response to localStorage.
},
ACTION.LOGIN_REQUEST_FAILURE,
],
},
});
};
I can see that the credentials are rightly stored in the localStorage of my application:
But they are not preserved when i redirect to a new url using window.open(process.env.NEW_SITE_URL)
.
How do i make sure that the credentials
object is carried over when redirecting to a new url?
I cannot use sessions and cookies due to the logic written in the app that i'm redirecting to. It only looks for credentials
in localStorage.