Skip to content

Instantly share code, notes, and snippets.

@vbguard
Created October 25, 2019 07:38
Show Gist options
  • Save vbguard/fda9e2020f12e1b828273efd4f16d4d1 to your computer and use it in GitHub Desktop.
Save vbguard/fda9e2020f12e1b828273efd4f16d4d1 to your computer and use it in GitHub Desktop.
function checkAuth(nextState, replaceState) {
let { loggedIn } = store.getState();
// check if the path isn't dashboard
// that way we can apply specific logic
// to display/render the path we want to
if (nextState.location.pathname !== '/dashboard') {
if (loggedIn) {
if (nextState.location.state && nextState.location.pathname) {
replaceState(null, nextState.location.pathname);
} else {
replaceState(null, '/');
}
}
} else {
// If the user is already logged in, forward them to the homepage
if (!loggedIn) {
if (nextState.location.state && nextState.location.pathname) {
replaceState(null, nextState.location.pathname);
} else {
replaceState(null, '/');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment