Skip to content

Instantly share code, notes, and snippets.

@compwron
Created November 22, 2019 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save compwron/03ba3c25f320082b7049ad78b0f15cfa to your computer and use it in GitHub Desktop.
Save compwron/03ba3c25f320082b7049ad78b0f15cfa to your computer and use it in GitHub Desktop.
hack for auth redirect w/ react-router 4 and redux-aut-wrapper
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