From 19098940f7984102581fd4feed09caf322004841 Mon Sep 17 00:00:00 2001 From: Matteo Vollero <99219448+monkeymatt0@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:04:34 +0200 Subject: [PATCH] chore: check currentUser and redirect to index if logged (#4021) * If to check currentUser and redirect to index if logged * Moved check into useEffect --- web/src/pages/SignIn.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/pages/SignIn.tsx b/web/src/pages/SignIn.tsx index 87f4b0f1c..ff55fd49d 100644 --- a/web/src/pages/SignIn.tsx +++ b/web/src/pages/SignIn.tsx @@ -7,7 +7,9 @@ import LocaleSelect from "@/components/LocaleSelect"; import PasswordSignInForm from "@/components/PasswordSignInForm"; import { identityProviderServiceClient } from "@/grpcweb"; import { absolutifyLink } from "@/helpers/utils"; +import useCurrentUser from "@/hooks/useCurrentUser"; import { useCommonContext } from "@/layouts/CommonContextProvider"; +import { Routes } from "@/router"; import { extractIdentityProviderIdFromName, useWorkspaceSettingStore } from "@/store/v1"; import { IdentityProvider, IdentityProvider_Type } from "@/types/proto/api/v1/idp_service"; import { WorkspaceGeneralSetting } from "@/types/proto/api/v1/workspace_setting_service"; @@ -16,6 +18,7 @@ import { useTranslate } from "@/utils/i18n"; const SignIn = () => { const t = useTranslate(); + const currentUser = useCurrentUser(); const commonContext = useCommonContext(); const workspaceSettingStore = useWorkspaceSettingStore(); const [identityProviderList, setIdentityProviderList] = useState([]); @@ -23,6 +26,9 @@ const SignIn = () => { workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL).generalSetting || WorkspaceGeneralSetting.fromPartial({}); useEffect(() => { + if (currentUser) { + window.location.href = Routes.ROOT; + } const fetchIdentityProviderList = async () => { const { identityProviders } = await identityProviderServiceClient.listIdentityProviders({}); setIdentityProviderList(identityProviders);