fix(web): /auth/login should skip flows if isAuthenticated is true

This commit is contained in:
41666 2021-03-14 16:01:42 -04:00
parent 2ef96d6575
commit d6646878f3

View file

@ -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<GuildSlug | null>(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 <div>Loading...</div>;