Skip to content

Commit

Permalink
move oauth redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarz2030 committed Jul 19, 2023
1 parent 35b323f commit f67b553
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 1 addition & 7 deletions src/components/CheckForToken/CheckForToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const CheckForToken = ({ children }) => {

if (storedState === state || process.env.NODE_ENV === 'development') {
setVerifying(true)
callback(authCode, dispatch).then(() => {
callback(authCode, dispatch, push).then(() => {
const queryParams = new URLSearchParams(location.search)

if (queryParams.has('code')) {
Expand All @@ -30,14 +30,8 @@ export const CheckForToken = ({ children }) => {
search: queryParams.toString(),
})

const redirectUrl = localStorage.getItem('redirect');

setVerifying(false)
localStorage.removeItem('state');

if (redirectUrl) {
push(redirectUrl)
}
}
}).catch(() => {
setVerifying(false)
Expand Down
8 changes: 5 additions & 3 deletions src/components/TaskPane/PublicTaskPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export class PublicTaskPane extends Component {
//render regular TaskPane for logged in users.
const loggedIn = localStorage.getItem('isLoggedIn')
if (loggedIn) {
<Redirect
to={`${this.match.url}`}
/>
return (
<Redirect
to={`${this.props.match.url}`}
/>
)
}

if (!_get(this.props, 'task.parent.parent')) {
Expand Down
9 changes: 8 additions & 1 deletion src/services/User/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export const fetchBasicUser = function(userId) {
*
* @param authCode - the token
*/
export const callback = async (authCode, dispatch) => {
export const callback = async (authCode, dispatch, push) => {
const resetURI =
`${process.env.REACT_APP_MAP_ROULETTE_SERVER_URL}/auth/callback?code=${authCode}`

Expand All @@ -337,6 +337,13 @@ export const callback = async (authCode, dispatch) => {
dispatch(fetchSavedChallenges(userId))
dispatch(fetchUserNotifications(userId))
subscribeToUserUpdates(dispatch, userId)

const redirectUrl = localStorage.getItem('redirect');

if (redirectUrl) {
push(redirectUrl)
localStorage.removeItem('redirects')
}
}).catch(
error => console.log(error)
).then(() => null)
Expand Down

0 comments on commit f67b553

Please sign in to comment.