Skip to content

The open alternative to Salesforce, designed for AI.

Stop the default domain from bouncing users back to their last workspace (#26260)

Thomas des Francs0691e6ca5642
diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
index b1110388b31..48edf0a8974 100644
--- a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
+++ b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
@@ -56,6 +56,7 @@ import { useLastAuthenticatedWorkspaceDomain } from '@/domain-manager/hooks/useL
import { useOrigin } from '@/domain-manager/hooks/useOrigin';
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
+import { isChooseWorkspaceActionRequested } from '@/auth/utils/isChooseWorkspaceActionRequested';
import { useLoadCurrentUser } from '@/users/hooks/useLoadCurrentUser';
import { i18n } from '@lingui/core';
import { useNavigate, useSearchParams } from 'react-router-dom';
@@ -156,7 +157,10 @@ export const useAuth = () => {
return;
}
- if (availableWorkspacesCount === 1) {
+ if (
+ availableWorkspacesCount === 1 &&
+ !isChooseWorkspaceActionRequested()
+ ) {
const targetWorkspace =
getFirstAvailableWorkspaces(availableWorkspaces);
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/constants/ChooseWorkspaceAction.ts b/packages/twenty-front/src/modules/auth/sign-in-up/constants/ChooseWorkspaceAction.ts
new file mode 100644
index 00000000000..9dc23da4af1
--- /dev/null
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/constants/ChooseWorkspaceAction.ts
@@ -0,0 +1 @@
+export const CHOOSE_WORKSPACE_ACTION = 'choose-workspace';
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/constants/SignInUpActionSearchParam.ts b/packages/twenty-front/src/modules/auth/sign-in-up/constants/SignInUpActionSearchParam.ts
new file mode 100644
index 00000000000..884e32e3cde
--- /dev/null
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/constants/SignInUpActionSearchParam.ts
@@ -0,0 +1 @@
+export const SIGN_IN_UP_ACTION_SEARCH_PARAM = 'action';
diff --git a/packages/twenty-front/src/modules/auth/utils/isChooseWorkspaceActionRequested.ts b/packages/twenty-front/src/modules/auth/utils/isChooseWorkspaceActionRequested.ts
new file mode 100644
index 00000000000..44a1f291401
--- /dev/null
+++ b/packages/twenty-front/src/modules/auth/utils/isChooseWorkspaceActionRequested.ts
@@ -0,0 +1,7 @@
+import { CHOOSE_WORKSPACE_ACTION } from '@/auth/sign-in-up/constants/ChooseWorkspaceAction';
+import { SIGN_IN_UP_ACTION_SEARCH_PARAM } from '@/auth/sign-in-up/constants/SignInUpActionSearchParam';
+
+export const isChooseWorkspaceActionRequested = () =>
+ new URLSearchParams(window.location.search).get(
+ SIGN_IN_UP_ACTION_SEARCH_PARAM,
+ ) === CHOOSE_WORKSPACE_ACTION;
diff --git a/packages/twenty-front/src/modules/domain-manager/hooks/useRedirectToDefaultDomain.ts b/packages/twenty-front/src/modules/domain-manager/hooks/useRedirectToDefaultDomain.ts
index a92f4665175..1f7e976a0d7 100644
--- a/packages/twenty-front/src/modules/domain-manager/hooks/useRedirectToDefaultDomain.ts
+++ b/packages/twenty-front/src/modules/domain-manager/hooks/useRedirectToDefaultDomain.ts
@@ -1,3 +1,5 @@
+import { CHOOSE_WORKSPACE_ACTION } from '@/auth/sign-in-up/constants/ChooseWorkspaceAction';
+import { SIGN_IN_UP_ACTION_SEARCH_PARAM } from '@/auth/sign-in-up/constants/SignInUpActionSearchParam';
import { returnToPathState } from '@/auth/states/returnToPathState';
import { useLastAuthenticatedWorkspaceDomain } from '@/domain-manager/hooks/useLastAuthenticatedWorkspaceDomain';
import { useReadDefaultDomainFromConfiguration } from '@/domain-manager/hooks/useReadDefaultDomainFromConfiguration';
@@ -19,6 +21,10 @@ export const useRedirectToDefaultDomain = () => {
const url = new URL(window.location.href);
if (url.hostname !== defaultDomain) {
setLastAuthenticateWorkspaceDomain(null);
+ url.searchParams.set(
+ SIGN_IN_UP_ACTION_SEARCH_PARAM,
+ CHOOSE_WORKSPACE_ACTION,
+ );
const returnToPath = store.get(returnToPathState.atom);
if (
diff --git a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx
index 56e80cca868..852f1a3ddc0 100644
--- a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx
+++ b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx
@@ -6,6 +6,7 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomState
import { useEffect, useCallback } from 'react';
import { useInitializeQueryParamState } from '@/app/hooks/useInitializeQueryParamState';
+import { isChooseWorkspaceActionRequested } from '@/auth/utils/isChooseWorkspaceActionRequested';
import { useGetPublicWorkspaceDataByDomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataByDomain';
import { useIsCurrentLocationOnDefaultDomain } from '@/domain-manager/hooks/useIsCurrentLocationOnDefaultDomain';
import { isDefined } from 'twenty-shared/utils';
@@ -67,6 +68,7 @@ export const WorkspaceProviderEffect = () => {
if (
isMultiWorkspaceEnabled &&
isDefaultDomain &&
+ !isChooseWorkspaceActionRequested() &&
isDefined(lastAuthenticatedWorkspaceDomain) &&
'workspaceUrl' in lastAuthenticatedWorkspaceDomain &&
isDefined(lastAuthenticatedWorkspaceDomain?.workspaceUrl)