erikras / erikras/react-redux-universal-hot-example

Store and state lost in next route on replace() inside onEnter

Open
#1,294 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.1k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

So, as in the boilerplate..

```
const requireLogin = (nextState, replace, cb) => {

if(!isLoggedIn) {
store.dispatch(getUserInfo(somePayLoad)).then(checkLoginStatus);
}
function checkLoginStatus() {
const {authorization: { user }} = store.getState();
if(!user.isSpecial && nextState.location.pathname === '/special') {
replace('/home');
}
cb();
}
}

```

So, when I `replace()`, and if the if condition `!user.isSpecial` fails, then it goes to the usual called route, access the user details that were fetched as in above code and also, I can easily call `logout` dispatcher I wrote whenever user wants to exit. But when if condition is passed, it replaces to `/home` page and opens(redirects) to home page successfully. But I can no longer have user details in `authorization` store. Neither I can call `logout` dispatcher.

How to achieve this?

Contributor guide

Open the contributing guide

Research direction

Start with the requireLogin onEnter flow shown in the issue, focusing on store.dispatch, replace('/home'), and the authorization state. Reproduce the redirect and check whether the fetched user details remain available afterward and whether logout can still dispatch; done means both behaviors work after replacement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react, redux
Domain
authentication, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.