From d6646878f329bfe1a9ad8f8489d7e63901ce2d08 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Sun, 14 Mar 2021 16:01:42 -0400 Subject: [PATCH] fix(web): /auth/login should skip flows if isAuthenticated is true --- packages/web/src/pages/auth/login.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/web/src/pages/auth/login.tsx b/packages/web/src/pages/auth/login.tsx index 0eae3a3..147bfd4 100644 --- a/packages/web/src/pages/auth/login.tsx +++ b/packages/web/src/pages/auth/login.tsx @@ -1,11 +1,14 @@ +import { redirectTo } from '@reach/router'; import { AuthLogin } from '@roleypoly/design-system/templates/auth-login'; import { GuildSlug } from '@roleypoly/types'; import React from 'react'; import { useApiContext } from '../../contexts/api/ApiContext'; +import { useSessionContext } from '../../contexts/session/SessionContext'; import { Title } from '../../utils/metaTitle'; const Login = () => { const { apiUrl, fetch } = useApiContext(); + const { isAuthenticated } = useSessionContext(); // If ?r is in query, then let's render the slug page // If not, redirect. const [guildSlug, setGuildSlug] = React.useState(null); @@ -17,6 +20,9 @@ const Login = () => { const redirectServerID = url.searchParams.get('r'); const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`; if (!redirectServerID) { + if (isAuthenticated) { + redirectTo('/servers'); + } window.location.href = redirectUrl; return; } @@ -33,7 +39,11 @@ const Login = () => { }; fetchGuildSlug(redirectServerID); - }, [apiUrl, fetch]); + + if (isAuthenticated) { + redirectTo(`/s/${redirectServerID}`); + } + }, [apiUrl, fetch, isAuthenticated]); if (guildSlug === null) { return
Loading...
;