diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
index 596d7a2566..9f557a8ca9 100644
--- a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
+++ b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts
@@ -26,12 +26,14 @@ import {
type AuthTokenPair,
} from '~/generated-metadata/graphql';
-import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { tokenPairState } from '@/auth/states/tokenPairState';
+import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
import { isAppEffectRedirectEnabledState } from '@/app/states/isAppEffectRedirectEnabledState';
import { useSignUpInNewWorkspace } from '@/auth/sign-in-up/hooks/useSignUpInNewWorkspace';
import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadedState';
+import { lastAuthenticatedMethodState } from '@/auth/states/lastAuthenticatedMethodState';
+import { loginTokenState } from '@/auth/states/loginTokenState';
import {
SignInUpStep,
signInUpStepState,
@@ -66,7 +68,6 @@ import { iconsState } from 'twenty-ui/display';
import { type AuthToken } from '~/generated/graphql';
import { cookieStorage } from '~/utils/cookie-storage';
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
-import { loginTokenState } from '@/auth/states/loginTokenState';
export const useAuth = () => {
const setTokenPair = useSetRecoilState(tokenPairState);
@@ -121,7 +122,7 @@ export const useAuth = () => {
const { loadMockedObjectMetadataItems } = useLoadMockedObjectMetadataItems();
const clearSession = useRecoilCallback(
- ({ snapshot }) =>
+ ({ snapshot, set }) =>
async () => {
const emptySnapshot = snapshot_UNSTABLE();
@@ -152,6 +153,9 @@ export const useAuth = () => {
const workspacePublicData = snapshot
.getLoadable(workspacePublicDataState)
.getValue();
+ const lastAuthenticatedMethod = snapshot
+ .getLoadable(lastAuthenticatedMethodState)
+ .getValue();
const initialSnapshot = emptySnapshot.map(({ set }) => {
set(iconsState, iconsValue);
@@ -174,12 +178,14 @@ export const useAuth = () => {
return undefined;
});
- goToRecoilSnapshot(initialSnapshot);
-
sessionStorage.clear();
localStorage.clear();
+
+ goToRecoilSnapshot(initialSnapshot);
+
+ set(lastAuthenticatedMethodState, lastAuthenticatedMethod);
+
await client.clearStore();
- // We need to explicitly clear the state to trigger the cookie deletion which include the parent domain
setLastAuthenticateWorkspaceDomain(null);
await loadMockedObjectMetadataItems();
navigate(AppPath.SignInUp);
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 d1c36f3b95..bc6981ce0c 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
@@ -4,39 +4,29 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Trans, useLingui } from '@lingui/react/macro';
import { motion } from 'framer-motion';
-import { useState } from 'react';
import { FormProvider } from 'react-hook-form';
-import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
+import { useRecoilValue } from 'recoil';
import { ClickToActionLink, UndecoratedLink } from 'twenty-ui/navigation';
import { useAuth } from '@/auth/hooks/useAuth';
-import { SignInUpEmailField } from '@/auth/sign-in-up/components/internal/SignInUpEmailField';
-import { SignInUpPasswordField } from '@/auth/sign-in-up/components/internal/SignInUpPasswordField';
+import { SignInUpWithCredentials } from '@/auth/sign-in-up/components/internal/SignInUpWithCredentials';
import { SignInUpWithGoogle } from '@/auth/sign-in-up/components/internal/SignInUpWithGoogle';
import { SignInUpWithMicrosoft } from '@/auth/sign-in-up/components/internal/SignInUpWithMicrosoft';
-import { useSignInUp } from '@/auth/sign-in-up/hooks/useSignInUp';
import { useSignInUpForm } from '@/auth/sign-in-up/hooks/useSignInUpForm';
import { useSignUpInNewWorkspace } from '@/auth/sign-in-up/hooks/useSignUpInNewWorkspace';
-import { signInUpModeState } from '@/auth/states/signInUpModeState';
import {
SignInUpStep,
signInUpStepState,
} from '@/auth/states/signInUpStepState';
-import { SignInUpMode } from '@/auth/types/signInUpMode';
import { getAvailableWorkspacePathAndSearchParams } from '@/auth/utils/availableWorkspacesUtils';
-import { isRequestingCaptchaTokenState } from '@/captcha/states/isRequestingCaptchaTokenState';
-import { useCaptcha } from '@/client-config/hooks/useCaptcha';
import { authProvidersState } from '@/client-config/states/authProvidersState';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
-import { isDefined } from 'twenty-shared/utils';
import {
Avatar,
HorizontalSeparator,
IconChevronRight,
IconPlus,
} from 'twenty-ui/display';
-import { Loader } from 'twenty-ui/feedback';
-import { MainButton } from 'twenty-ui/input';
import { type AvailableWorkspace } from '~/generated/graphql';
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
@@ -46,13 +36,6 @@ const StyledContentContainer = styled(motion.div)`
min-width: 200px;
`;
-const StyledForm = styled.form`
- align-items: center;
- display: flex;
- flex-direction: column;
- width: 100%;
-`;
-
const StyledWorkspaceContainer = styled.div`
background-color: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.light};
@@ -147,43 +130,12 @@ export const SignInUpGlobalScopeForm = () => {
const { signOut } = useAuth();
const { createWorkspace } = useSignUpInNewWorkspace();
- const setSignInUpStep = useSetRecoilState(signInUpStepState);
- const [signInUpMode] = useRecoilState(signInUpModeState);
const availableWorkspaces = useRecoilValue(availableWorkspacesState);
const theme = useTheme();
const { t } = useLingui();
- const isRequestingCaptchaToken = useRecoilValue(
- isRequestingCaptchaTokenState,
- );
- const { isCaptchaReady } = useCaptcha();
-
- const [showErrors, setShowErrors] = useState(false);
-
const { form } = useSignInUpForm();
- const { submitCredentials, continueWithCredentials } = useSignInUp(form);
-
- const handleSubmit = async () => {
- if (isDefined(form?.formState?.errors?.email)) {
- setShowErrors(true);
- return;
- }
-
- if (signInUpStep === SignInUpStep.Password) {
- await submitCredentials(form.getValues());
- return;
- }
-
- await continueWithCredentials();
- };
-
- const onEmailChange = (email: string) => {
- if (email !== form.getValues('email')) {
- setSignInUpStep(SignInUpStep.Email);
- }
- };
-
const getAvailableWorkspaceUrl = (availableWorkspace: AvailableWorkspace) => {
const { pathname, searchParams } = getAvailableWorkspacePathAndSearchParams(
availableWorkspace,
@@ -263,48 +215,23 @@ export const SignInUpGlobalScopeForm = () => {
{signInUpStep !== SignInUpStep.WorkspaceSelection && (