The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix infinite redirect loop when logging out of a suspended workspace (#22949)
Charles Bochet7ec7774087b6
diff --git a/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx b/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsxindex d7862eb45c8..dea9cdc1d07 100644--- a/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx+++ b/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx@@ -11,10 +11,19 @@ import {results,token,} from '@/auth/hooks/__mocks__/useAuth';+import {+ type CurrentUser,+ currentUserState,+} from '@/auth/states/currentUserState';+import {+ type CurrentWorkspace,+ currentWorkspaceState,+} from '@/auth/states/currentWorkspaceState';import { returnToPathState } from '@/auth/states/returnToPathState';import { SnackBarComponentInstanceContext } from '@/ui/feedback/snack-bar-manager/contexts/SnackBarComponentInstanceContext';import { renderHook } from '@testing-library/react';import { getDefaultStore } from 'jotai';+import { WorkspaceActivationStatus } from 'twenty-shared/workspace';const redirectSpy = jest.fn();@@ -184,6 +193,13 @@ describe('useAuth', () => {it('should handle sign-out', async () => {sessionStorage.setItem('lingering-key', 'should-be-cleared');+ getDefaultStore().set(currentWorkspaceState.atom, {+ id: 'workspace-id',+ activationStatus: WorkspaceActivationStatus.SUSPENDED,+ } as CurrentWorkspace);+ getDefaultStore().set(currentUserState.atom, {+ id: 'user-id',+ } as CurrentUser);const { result } = renderHooks();@@ -192,6 +208,8 @@ describe('useAuth', () => {});expect(sessionStorage.length).toBe(0);+ expect(getDefaultStore().get(currentWorkspaceState.atom)).toBeNull();+ expect(getDefaultStore().get(currentUserState.atom)).toBeNull();});it('should handle credential sign-up', async () => {diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.tsindex 13f628a9a6f..6cb40778834 100644--- a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts+++ b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts@@ -22,6 +22,10 @@ import {VerifyEmailAndGetWorkspaceAgnosticTokenDocument,} from '~/generated-metadata/graphql';+import { currentUserState } from '@/auth/states/currentUserState';+import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';+import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { returnToPathState } from '@/auth/states/returnToPathState';import { tokenPairState } from '@/auth/states/tokenPairState';import { clearSessionLocalStorageKeys } from '@/auth/utils/clearSessionLocalStorageKeys';@@ -111,8 +115,12 @@ export const useAuth = () => {const clearSession = useCallback(() => {sessionStorage.clear();- clearSessionLocalStorageKeys();store.set(tokenPairState.atom, null);+ store.set(currentUserState.atom, null);+ store.set(currentWorkspaceState.atom, null);+ store.set(currentWorkspaceMemberState.atom, null);+ store.set(currentUserWorkspaceState.atom, null);+ clearSessionLocalStorageKeys();setLastAuthenticateWorkspaceDomain(null);window.location.assign(AppPath.SignInUp);}, [store, setLastAuthenticateWorkspaceDomain]);