diff --git a/packages/console/src/cloud/pages/Main/index.tsx b/packages/console/src/cloud/pages/Main/index.tsx index a31114f80..47d65e765 100644 --- a/packages/console/src/cloud/pages/Main/index.tsx +++ b/packages/console/src/cloud/pages/Main/index.tsx @@ -1,10 +1,12 @@ import { useLogto } from '@logto/react'; import type { TenantInfo } from '@logto/schemas'; +import { conditional, yes } from '@silverhand/essentials'; import { useContext, useEffect } from 'react'; -import { useHref } from 'react-router-dom'; +import { useHref, useSearchParams } from 'react-router-dom'; import { useCloudApi } from '@/cloud/hooks/use-cloud-api'; import AppLoading from '@/components/AppLoading'; +import { searchKeys } from '@/consts'; import { TenantsContext } from '@/contexts/TenantsProvider'; import Redirect from './Redirect'; @@ -44,15 +46,20 @@ const Protected = () => { }; const Main = () => { + const [searchParameters] = useSearchParams(); const { isAuthenticated, isLoading, signIn } = useLogto(); const { currentTenantId } = useContext(TenantsContext); const href = useHref(currentTenantId + '/callback'); useEffect(() => { if (!isLoading && !isAuthenticated) { - void signIn(new URL(href, window.location.origin).toString()); + const isSignUpMode = yes(searchParameters.get(searchKeys.signUp)); + void signIn( + new URL(href, window.location.origin).toString(), + conditional(isSignUpMode && 'signUp') + ); } - }, [href, isAuthenticated, isLoading, signIn]); + }, [href, isAuthenticated, isLoading, searchParameters, signIn]); if (!isAuthenticated) { return ; diff --git a/packages/console/src/containers/AppContent/index.tsx b/packages/console/src/containers/AppContent/index.tsx index 56ed811ff..0799a70f8 100644 --- a/packages/console/src/containers/AppContent/index.tsx +++ b/packages/console/src/containers/AppContent/index.tsx @@ -1,13 +1,12 @@ import { LogtoClientError, LogtoError, useLogto } from '@logto/react'; -import { conditional, yes } from '@silverhand/essentials'; +import { conditional } from '@silverhand/essentials'; import { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { Outlet, useHref, useLocation, useNavigate, useSearchParams } from 'react-router-dom'; +import { Outlet, useHref, useLocation, useNavigate } from 'react-router-dom'; import AppError from '@/components/AppError'; import AppLoading from '@/components/AppLoading'; import SessionExpired from '@/components/SessionExpired'; -import { searchKeys } from '@/consts'; import { isCloud } from '@/consts/cloud'; import useConfigs from '@/hooks/use-configs'; import useScroll from '@/hooks/use-scroll'; @@ -30,7 +29,6 @@ const AppContent = () => { const location = useLocation(); const navigate = useNavigate(); - const [searchParameters] = useSearchParams(); const { firstItem } = useSidebarMenuItems(); const scrollableContent = useRef(null); const { scrollTop } = useScroll(scrollableContent.current); @@ -38,14 +36,9 @@ const AppContent = () => { useEffect(() => { if (!isAuthenticated && !isLogtoLoading) { - const signUpFirst = searchParameters.get(searchKeys.signUp); - - void signIn( - new URL(href, window.location.origin).toString(), - conditional(yes(signUpFirst) && 'signUp') - ); + void signIn(new URL(href, window.location.origin).toString()); } - }, [href, isAuthenticated, isLogtoLoading, searchParameters, signIn]); + }, [href, isAuthenticated, isLogtoLoading, signIn]); useEffect(() => { // Navigate to the first menu item after configs are loaded.