Skip to content

Instantly share code, notes, and snippets.

@compwron compwron/hack.js
Created Nov 22, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.