Created
October 25, 2019 07:38
-
-
Save vbguard/fda9e2020f12e1b828273efd4f16d4d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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