From 3a36d7a85dc7f581940b9986cba0e0803792193f Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Sat, 13 Mar 2021 16:48:50 -0500 Subject: [PATCH] feat(web): wire up discord auth button --- packages/web/src/pages/auth/login.tsx | 15 +++++++++++++-- packages/web/src/pages/machinery/new-session.tsx | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/web/src/pages/auth/login.tsx b/packages/web/src/pages/auth/login.tsx index 1ff960f..408910e 100644 --- a/packages/web/src/pages/auth/login.tsx +++ b/packages/web/src/pages/auth/login.tsx @@ -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(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
Loading...
; } - return {}} />; + return ( + {}} + discordOAuthLink={oauthLink} + /> + ); }; export default Login; diff --git a/packages/web/src/pages/machinery/new-session.tsx b/packages/web/src/pages/machinery/new-session.tsx index 5075e2f..9d426c2 100644 --- a/packages/web/src/pages/machinery/new-session.tsx +++ b/packages/web/src/pages/machinery/new-session.tsx @@ -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 || '/'; } });