From f4c5d03b989d2db7a01fa85221957583681ff371 Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Thu, 5 Dec 2024 16:24:24 +0100 Subject: [PATCH] fix(): redirect loop + signout (#8899) --- .../src/modules/auth/hooks/useAuth.ts | 5 +++ .../components/SignInUpGlobalScopeForm.tsx | 32 ++++++++----------- ...adWorkspaceSubdomainFromCurrentLocation.ts | 1 + .../components/WorkspaceProviderEffect.tsx | 6 +++- .../twenty-front/src/utils/recoil-effects.ts | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts index 8598fe638..aff5d35e2 100644 --- a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts +++ b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts @@ -46,6 +46,7 @@ import { useLastAuthenticatedWorkspaceDomain } from '@/domain-manager/hooks/useL import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState'; import { useIsCurrentLocationOnAWorkspaceSubdomain } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspaceSubdomain'; import { useReadWorkspaceSubdomainFromCurrentLocation } from '@/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation'; +import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState'; export const useAuth = () => { const setTokenPair = useSetRecoilState(tokenPairState); @@ -105,6 +106,9 @@ export const useAuth = () => { const isMultiWorkspaceEnabled = snapshot .getLoadable(isMultiWorkspaceEnabledState) .getValue(); + const domainConfiguration = snapshot + .getLoadable(domainConfigurationState) + .getValue(); const initialSnapshot = emptySnapshot.map(({ set }) => { set(iconsState, iconsValue); set(authProvidersState, authProvidersValue); @@ -119,6 +123,7 @@ export const useAuth = () => { set(clientConfigApiStatusState, clientConfigApiStatus); set(isCurrentUserLoadedState, isCurrentUserLoaded); set(isMultiWorkspaceEnabledState, isMultiWorkspaceEnabled); + set(domainConfigurationState, domainConfiguration); return undefined; }); goToRecoilSnapshot(initialSnapshot); diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx index 9bdfa73fc..08eb15e34 100644 --- a/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx +++ b/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx @@ -116,24 +116,20 @@ export const SignInUpGlobalScopeForm = () => { return ( <> - <> - } - title="Continue with Google" - onClick={signInWithGoogle} - fullWidth - /> - - - <> - } - title="Continue with Microsoft" - onClick={signInWithMicrosoft} - fullWidth - /> - - + } + title="Continue with Google" + onClick={signInWithGoogle} + fullWidth + /> + + } + title="Continue with Microsoft" + onClick={signInWithMicrosoft} + fullWidth + /> + {/* eslint-disable-next-line react/jsx-props-no-spreading */} diff --git a/packages/twenty-front/src/modules/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation.ts b/packages/twenty-front/src/modules/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation.ts index 7fb3eda88..fc053da09 100644 --- a/packages/twenty-front/src/modules/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation.ts +++ b/packages/twenty-front/src/modules/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation.ts @@ -7,6 +7,7 @@ export const useReadWorkspaceSubdomainFromCurrentLocation = () => { const domainConfiguration = useRecoilValue(domainConfigurationState); const { isOnAWorkspaceSubdomain } = useIsCurrentLocationOnAWorkspaceSubdomain(); + if (!isDefined(domainConfiguration.frontDomain)) { throw new Error('frontDomain is not defined'); } diff --git a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx index eb5d10319..3d43fc268 100644 --- a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx +++ b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx @@ -24,7 +24,11 @@ export const WorkspaceProviderEffect = () => { const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState); useEffect(() => { - if (isMultiWorkspaceEnabled && isDefined(workspacePublicData?.subdomain)) { + if ( + isMultiWorkspaceEnabled && + isDefined(workspacePublicData?.subdomain) && + workspacePublicData.subdomain !== workspaceSubdomain + ) { redirectToWorkspaceDomain(workspacePublicData.subdomain); } }, [ diff --git a/packages/twenty-front/src/utils/recoil-effects.ts b/packages/twenty-front/src/utils/recoil-effects.ts index e9e8b19ef..5d77b27b0 100644 --- a/packages/twenty-front/src/utils/recoil-effects.ts +++ b/packages/twenty-front/src/utils/recoil-effects.ts @@ -45,9 +45,9 @@ export const cookieStorageEffect = ): AtomEffect => ({ setSelf, onSet }) => { const savedValue = cookieStorage.getItem(key); - if ( isDefined(savedValue) && + savedValue.length !== 0 && (!isDefined(hooks?.validateInitFn) || hooks.validateInitFn(JSON.parse(savedValue))) ) {