mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
fix(web): /auth/login should skip flows if isAuthenticated is true
This commit is contained in:
parent
2ef96d6575
commit
d6646878f3
1 changed files with 11 additions and 1 deletions
|
@ -1,11 +1,14 @@
|
||||||
|
import { redirectTo } from '@reach/router';
|
||||||
import { AuthLogin } from '@roleypoly/design-system/templates/auth-login';
|
import { AuthLogin } from '@roleypoly/design-system/templates/auth-login';
|
||||||
import { GuildSlug } from '@roleypoly/types';
|
import { GuildSlug } from '@roleypoly/types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useApiContext } from '../../contexts/api/ApiContext';
|
import { useApiContext } from '../../contexts/api/ApiContext';
|
||||||
|
import { useSessionContext } from '../../contexts/session/SessionContext';
|
||||||
import { Title } from '../../utils/metaTitle';
|
import { Title } from '../../utils/metaTitle';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const { apiUrl, fetch } = useApiContext();
|
const { apiUrl, fetch } = useApiContext();
|
||||||
|
const { isAuthenticated } = useSessionContext();
|
||||||
// If ?r is in query, then let's render the slug page
|
// If ?r is in query, then let's render the slug page
|
||||||
// If not, redirect.
|
// If not, redirect.
|
||||||
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
||||||
|
@ -17,6 +20,9 @@ const Login = () => {
|
||||||
const redirectServerID = url.searchParams.get('r');
|
const redirectServerID = url.searchParams.get('r');
|
||||||
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
||||||
if (!redirectServerID) {
|
if (!redirectServerID) {
|
||||||
|
if (isAuthenticated) {
|
||||||
|
redirectTo('/servers');
|
||||||
|
}
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +39,11 @@ const Login = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchGuildSlug(redirectServerID);
|
fetchGuildSlug(redirectServerID);
|
||||||
}, [apiUrl, fetch]);
|
|
||||||
|
if (isAuthenticated) {
|
||||||
|
redirectTo(`/s/${redirectServerID}`);
|
||||||
|
}
|
||||||
|
}, [apiUrl, fetch, isAuthenticated]);
|
||||||
|
|
||||||
if (guildSlug === null) {
|
if (guildSlug === null) {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue