Skip to content

Commit

Permalink
[JN-499] prevent multiple hub oauth redirects (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
devonbush authored Aug 15, 2023
1 parent 218ee9c commit 92c7f72
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ui-participant/src/login/RedirectFromOAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export const RedirectFromOAuth = () => {
// * handle possible study enrollment
// * navigate to the hub
// TODO: remember where the user was trying to go and navigate there instead of hard-coding /hub

const email = auth.user.profile.email as string
const accessToken = auth.user.access_token

// Register or login
const loginResult = auth.user.profile.newUser
? await Api.register({ preRegResponseId, email, accessToken })
: await Api.tokenLogin(accessToken)

loginUser(loginResult, accessToken)

// Decide if there's a study that has either been explicitly selected or is implicit because it's the only one
Expand Down Expand Up @@ -94,7 +96,12 @@ export const RedirectFromOAuth = () => {
}

handleRedirectFromOauth()
})
/**
* only process redirect logic if the auth token has changed. Previously, we were redirecting
* on all rerenders, which was leading to multiple redirects if, for example, the useUser() was
* updated in response to the loginUser() call
*/
}, [auth.user?.access_token])

return <PageLoadingIndicator />
}

0 comments on commit 92c7f72

Please sign in to comment.