Created
November 22, 2019 22:56
-
-
Save compwron/03ba3c25f320082b7049ad78b0f15cfa to your computer and use it in GitHub Desktop.
hack for auth redirect w/ react-router 4 and redux-aut-wrapper
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 handleAuthenticated (dispatch) { | |
lock.on('authenticated', ({ accessToken, idToken, state }) => { | |
lock.getUserInfo(accessToken, (error, user) => { | |
if (error) { | |
return dispatch(lockError(error)) | |
} | |
setUser(user) | |
setToken(idToken) | |
let redirect = null | |
try { | |
const parsedState = JSON.parse(atob(state)) | |
redirect = parsedState.redirect | |
} catch (_) { | |
// NOOP | |
} | |
dispatch(lockSuccess(user, idToken)) | |
lock.hide() | |
if (redirect !== null) { | |
const correctUrl = redirect.replace('?redirect=', '') | |
// a hack to make redirect-on-login work | |
history.replace(correctUrl) // TODO improve this | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment