Skip to content

The open alternative to Salesforce, designed for AI.

Fix v2 onboarding dropping to v1 after connecting email (#22351)

Raphaël Bosif08b87c478ef
diff --git a/packages/twenty-front/src/modules/auth/states/__tests__/isOnboardingV2State.test.ts b/packages/twenty-front/src/modules/auth/states/__tests__/isOnboardingV2State.test.ts
new file mode 100644
index 00000000000..0201b574b8a
--- /dev/null
+++ b/packages/twenty-front/src/modules/auth/states/__tests__/isOnboardingV2State.test.ts
@@ -0,0 +1,49 @@
+import { createStore } from 'jotai';
+
+import { type isOnboardingV2State as IsOnboardingV2State } from '@/auth/states/isOnboardingV2State';
+
+const loadAtom = (): typeof IsOnboardingV2State => {
+ let state: typeof IsOnboardingV2State | undefined;
+
+ jest.isolateModules(() => {
+ state = require('@/auth/states/isOnboardingV2State').isOnboardingV2State;
+ });
+
+ if (state === undefined) {
+ throw new Error('Failed to load isOnboardingV2State');
+ }
+
+ return state;
+};
+
+describe('isOnboardingV2State', () => {
+ afterEach(() => {
+ sessionStorage.clear();
+ jest.resetModules();
+ });
+
+ it('hydrates from sessionStorage on load so the flag survives the email-connect OAuth round-trip', () => {
+ sessionStorage.setItem('isOnboardingV2State', JSON.stringify(true));
+
+ const isOnboardingV2State = loadAtom();
+
+ expect(createStore().get(isOnboardingV2State.atom)).toBe(true);
+ });
+
+ it('writes through to sessionStorage when set', () => {
+ const isOnboardingV2State = loadAtom();
+ const store = createStore();
+
+ store.set(isOnboardingV2State.atom, true);
+
+ expect(sessionStorage.getItem('isOnboardingV2State')).toBe(
+ JSON.stringify(true),
+ );
+ });
+
+ it('defaults to false when nothing is persisted', () => {
+ const isOnboardingV2State = loadAtom();
+
+ expect(createStore().get(isOnboardingV2State.atom)).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/auth/states/isOnboardingV2State.ts b/packages/twenty-front/src/modules/auth/states/isOnboardingV2State.ts
index 434a4202c72..dd35a5437c4 100644
--- a/packages/twenty-front/src/modules/auth/states/isOnboardingV2State.ts
+++ b/packages/twenty-front/src/modules/auth/states/isOnboardingV2State.ts
@@ -3,4 +3,5 @@ import { createAtomState } from '@/ui/utilities/state/jotai/utils/createAtomStat
export const isOnboardingV2State = createAtomState<boolean>({
key: 'isOnboardingV2State',
defaultValue: false,
+ useSessionStorage: true,
});