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...
;