Skip to content

The open alternative to Salesforce, designed for AI.

Surface structured login verification errors (#25080)

Félix Malfait8dd951b0cfed
diff --git a/packages/twenty-front/src/modules/auth/hooks/__tests__/useVerifyLogin.test.ts b/packages/twenty-front/src/modules/auth/hooks/__tests__/useVerifyLogin.test.ts
index 6f682c8002a..f42eab5d276 100644
--- a/packages/twenty-front/src/modules/auth/hooks/__tests__/useVerifyLogin.test.ts
+++ b/packages/twenty-front/src/modules/auth/hooks/__tests__/useVerifyLogin.test.ts
@@ -1,5 +1,6 @@
import { i18n } from '@lingui/core';
import { I18nProvider } from '@lingui/react';
+import { CombinedGraphQLErrors } from '@apollo/client/errors';
import { renderHook } from '@testing-library/react';
import { Provider as JotaiProvider } from 'jotai';
@@ -70,7 +71,7 @@ describe('useVerifyLogin', () => {
expect(mockGetAuthTokensFromLoginToken).toHaveBeenCalledWith('test-token');
});
- it('should handle verification error', async () => {
+ it('should handle a non-GraphQL verification error', async () => {
const error = new Error('Verification failed');
mockGetAuthTokensFromLoginToken.mockRejectedValueOnce(error);
@@ -83,4 +84,20 @@ describe('useVerifyLogin', () => {
});
expect(mockNavigate).toHaveBeenCalledWith(AppPath.SignInUp);
});
+
+ it('should preserve a GraphQL verification error for the snackbar', async () => {
+ const error = new CombinedGraphQLErrors({
+ errors: [{ message: 'Session could not be created' }],
+ });
+ mockGetAuthTokensFromLoginToken.mockRejectedValueOnce(error);
+
+ const { result } = renderHooks();
+
+ await result.current.verifyLoginToken('test-token');
+
+ expect(mockEnqueueErrorSnackBar).toHaveBeenCalledWith({
+ apolloError: error,
+ });
+ expect(mockNavigate).toHaveBeenCalledWith(AppPath.SignInUp);
+ });
});
diff --git a/packages/twenty-front/src/modules/auth/hooks/useVerifyLogin.ts b/packages/twenty-front/src/modules/auth/hooks/useVerifyLogin.ts
index 6bed3288114..9eae73ef5f6 100644
--- a/packages/twenty-front/src/modules/auth/hooks/useVerifyLogin.ts
+++ b/packages/twenty-front/src/modules/auth/hooks/useVerifyLogin.ts
@@ -2,6 +2,7 @@ import { isAppEffectRedirectEnabledState } from '@/app/states/isAppEffectRedirec
import { useAuth } from '@/auth/hooks/useAuth';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { CombinedGraphQLErrors } from '@apollo/client/errors';
import { useLingui } from '@lingui/react/macro';
import { AppPath } from 'twenty-shared/types';
import { useNavigateApp } from '~/hooks/useNavigateApp';
@@ -20,10 +21,14 @@ export const useVerifyLogin = () => {
setIsAppEffectRedirectEnabled(false);
try {
await getAuthTokensFromLoginToken(loginToken);
- } catch {
- enqueueErrorSnackBar({
- message: t`Authentication failed`,
- });
+ } catch (error) {
+ enqueueErrorSnackBar(
+ CombinedGraphQLErrors.is(error)
+ ? { apolloError: error }
+ : {
+ message: t`Authentication failed`,
+ },
+ );
navigate(AppPath.SignInUp);
} finally {
setIsAppEffectRedirectEnabled(true);