feat(web): wire up discord auth button

This commit is contained in:
41666 2021-03-13 16:48:50 -05:00
parent 0a399938d6
commit 3a36d7a85d
2 changed files with 16 additions and 3 deletions

View file

@ -8,16 +8,21 @@ const Login = () => {
// If ?r is in query, then let's render the slug page
// If not, redirect.
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
const [oauthLink, setOauthLink] = React.useState(`${apiUrl}/login-bounce`);
React.useEffect(() => {
const url = new URL(window.location.href);
const callbackHost = new URL('/', url);
const redirectServerID = url.searchParams.get('r');
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
if (!redirectServerID) {
window.location.href = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
window.location.href = redirectUrl;
return;
}
setOauthLink(redirectUrl);
localStorage.setItem('rp_postauth_redirect', `/s/${redirectServerID}`);
const fetchGuildSlug = async (id: string) => {
const response = await fetch(`/get-slug/${id}`);
if (response.status === 200) {
@ -33,7 +38,13 @@ const Login = () => {
return <div>Loading...</div>;
}
return <AuthLogin guildSlug={guildSlug} onSendSecretCode={() => {}} />;
return (
<AuthLogin
guildSlug={guildSlug}
onSendSecretCode={() => {}}
discordOAuthLink={oauthLink}
/>
);
};
export default Login;

View file

@ -5,8 +5,10 @@ const NewSession = () => {
const url = new URL(window.location.href);
const id = url.searchParams.get('session_id');
if (id) {
window.location.href = '/';
localStorage.setItem('rp_session_key', id);
const redirectUrl = localStorage.getItem('rp_postauth_redirect');
window.location.href = redirectUrl || '/';
}
});