Skip to content

The open alternative to Salesforce, designed for AI.

fix(): redirect loop + signout (#8899)

Antoine Moreauxf4c5d03b989d
diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
index 8598fe63848..aff5d35e2f5 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 9bdfa73fc9c..08eb15e34f3 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 (
<>
<StyledContentContainer>
- <>
- <MainButton
- Icon={() => <IconGoogle size={theme.icon.size.lg} />}
- title="Continue with Google"
- onClick={signInWithGoogle}
- fullWidth
- />
- <HorizontalSeparator visible={false} />
- </>
- <>
- <MainButton
- Icon={() => <IconMicrosoft size={theme.icon.size.lg} />}
- title="Continue with Microsoft"
- onClick={signInWithMicrosoft}
- fullWidth
- />
- <HorizontalSeparator visible={false} />
- </>
+ <MainButton
+ Icon={() => <IconGoogle size={theme.icon.size.lg} />}
+ title="Continue with Google"
+ onClick={signInWithGoogle}
+ fullWidth
+ />
+ <HorizontalSeparator visible={false} />
+ <MainButton
+ Icon={() => <IconMicrosoft size={theme.icon.size.lg} />}
+ title="Continue with Microsoft"
+ onClick={signInWithMicrosoft}
+ fullWidth
+ />
+ <HorizontalSeparator visible={false} />
<HorizontalSeparator visible />
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<FormProvider {...form}>
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 7fb3eda882d..fc053da0931 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 eb5d1031935..3d43fc2680f 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 e9e8b19ef05..5d77b27b05f 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<T | null> =>
({ setSelf, onSet }) => {
const savedValue = cookieStorage.getItem(key);
-
if (
isDefined(savedValue) &&
+ savedValue.length !== 0 &&
(!isDefined(hooks?.validateInitFn) ||
hooks.validateInitFn(JSON.parse(savedValue)))
) {