Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5798035
commit 4546534
Showing
7 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState, useEffect, useRef } from 'react'; | ||
import { useParams, Navigate, useLocation } from 'react-router-dom'; | ||
import { useUser } from '../contexts/UserProvider'; | ||
import { useFlash } from '../contexts/FlashProvider'; | ||
|
||
export default function SocialCallbackPage() { | ||
const { oauth2Login } = useUser(); | ||
const flash = useFlash(); | ||
const location = useLocation(); | ||
const firstRender = useRef(true); | ||
|
||
const [redirectUrl, setRedirectUrl] = useState(null); | ||
const { provider } = useParams(); | ||
const searchParams = new URLSearchParams(location.search); | ||
const code = searchParams.get('code'); | ||
const state = searchParams.get('state'); | ||
|
||
useEffect(() => { | ||
if (!firstRender.current) { | ||
return; | ||
} | ||
firstRender.current = false; | ||
|
||
(async () => { | ||
const result = await oauth2Login(provider, code, state); | ||
if (result === 'fail') { | ||
flash('Could not log you in.', 'danger'); | ||
} | ||
else if (result === 'ok') { | ||
let next = '/'; | ||
if (location.state && location.state.next) { | ||
next = location.state.next; | ||
} | ||
setRedirectUrl(next); | ||
} | ||
|
||
})(); | ||
}, [oauth2Login, provider, code, state, flash, location]); | ||
|
||
return redirectUrl === null ? null : <Navigate to={redirectUrl} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import { useApi } from '../contexts/ApiProvider'; | ||
|
||
export default function SocialLoginPage() { | ||
const { provider } = useParams(); | ||
const api = useApi(); | ||
|
||
window.location.href = api.base_url + `/tokens/oauth2/${provider}`; | ||
return null; | ||
} |