Skip to content

Commit

Permalink
🐛 Fix login redirection (zenika-open-source#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorname authored May 17, 2019
1 parent c4ab193 commit 0e6babe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion client/src/contexts/Auth/AuthProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AuthProvider extends Component {
try {
const authResult = await auth.parseHash(hash)

const { redirectTo } = auth.popStateBeforeLogin()
const { redirectTo } = auth.getStateBeforeLogin()

const { data } = await authQL(authResult.idToken)

Expand All @@ -87,6 +87,8 @@ class AuthProvider extends Component {
}
)

auth.clearStateBeforeLogin()

history.push(redirectTo || '')
} catch (err) {
alert.pushError('Authentication failed: ' + JSON.stringify(err.message), err)
Expand Down
8 changes: 5 additions & 3 deletions client/src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ class Auth {
localStorage.state_before_login = JSON.stringify(state)
}

popStateBeforeLogin() {
const state = JSON.parse(localStorage.state_before_login || '{}')
getStateBeforeLogin() {
return JSON.parse(localStorage.state_before_login || '{}')
}

clearStateBeforeLogin() {
localStorage.removeItem('state_before_login')
return state
}
}

Expand Down

0 comments on commit 0e6babe

Please sign in to comment.