From 1dc6f7dd09082480bbbe071c91c847d806e657b9 Mon Sep 17 00:00:00 2001 From: Alan Daniel Date: Mon, 4 May 2026 19:28:18 -0400 Subject: [PATCH] fix: double wrap reponse of guest session handler (#4438) * v0.6.29: login improvements, posthog telemetry (#4026) * feat(posthog): Add tracking on mothership abort (#4023) Co-authored-by: Theodore Li * fix(login): fix captcha headers for manual login (#4025) * fix(signup): fix turnstile key loading * fix(login): fix captcha header passing * Catch user already exists, remove login form captcha * fix double wrap reponse of guest session handler * remove dead code, and fix test --------- Co-authored-by: Waleed Co-authored-by: Theodore Li Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti Co-authored-by: Theodore Li --- apps/sim/app/api/auth/[...all]/route.test.ts | 16 ++++++---------- apps/sim/app/api/auth/[...all]/route.ts | 4 ++-- apps/sim/lib/auth/anonymous.ts | 4 ---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/apps/sim/app/api/auth/[...all]/route.test.ts b/apps/sim/app/api/auth/[...all]/route.test.ts index d9aa74cab9..f87f1a0167 100644 --- a/apps/sim/app/api/auth/[...all]/route.test.ts +++ b/apps/sim/app/api/auth/[...all]/route.test.ts @@ -8,11 +8,9 @@ const handlerMocks = vi.hoisted(() => ({ betterAuthGET: vi.fn(), betterAuthPOST: vi.fn(), ensureAnonymousUserExists: vi.fn(), - createAnonymousGetSessionResponse: vi.fn(() => ({ - data: { - user: { id: 'anon' }, - session: { id: 'anon-session' }, - }, + createAnonymousSession: vi.fn(() => ({ + user: { id: 'anon' }, + session: { id: 'anon-session' }, })), isAuthDisabled: false, })) @@ -30,7 +28,7 @@ vi.mock('@/lib/auth', () => ({ vi.mock('@/lib/auth/anonymous', () => ({ ensureAnonymousUserExists: handlerMocks.ensureAnonymousUserExists, - createAnonymousGetSessionResponse: handlerMocks.createAnonymousGetSessionResponse, + createAnonymousSession: handlerMocks.createAnonymousSession, })) vi.mock('@/lib/core/config/feature-flags', () => ({ @@ -63,10 +61,8 @@ describe('auth catch-all route (DISABLE_AUTH get-session)', () => { expect(handlerMocks.ensureAnonymousUserExists).toHaveBeenCalledTimes(1) expect(handlerMocks.betterAuthGET).not.toHaveBeenCalled() expect(json).toEqual({ - data: { - user: { id: 'anon' }, - session: { id: 'anon-session' }, - }, + user: { id: 'anon' }, + session: { id: 'anon-session' }, }) }) diff --git a/apps/sim/app/api/auth/[...all]/route.ts b/apps/sim/app/api/auth/[...all]/route.ts index b09ce7e7e6..6ff9bfd6db 100644 --- a/apps/sim/app/api/auth/[...all]/route.ts +++ b/apps/sim/app/api/auth/[...all]/route.ts @@ -1,7 +1,7 @@ import { toNextJsHandler } from 'better-auth/next-js' import { type NextRequest, NextResponse } from 'next/server' import { auth } from '@/lib/auth' -import { createAnonymousGetSessionResponse, ensureAnonymousUserExists } from '@/lib/auth/anonymous' +import { createAnonymousSession, ensureAnonymousUserExists } from '@/lib/auth/anonymous' import { isAuthDisabled } from '@/lib/core/config/feature-flags' import { withRouteHandler } from '@/lib/core/utils/with-route-handler' @@ -24,7 +24,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => { if (path === 'get-session' && isAuthDisabled) { await ensureAnonymousUserExists() - return NextResponse.json(createAnonymousGetSessionResponse()) + return NextResponse.json(createAnonymousSession()) } return betterAuthGET(request) diff --git a/apps/sim/lib/auth/anonymous.ts b/apps/sim/lib/auth/anonymous.ts index 839e65487e..7504ee7fd6 100644 --- a/apps/sim/lib/auth/anonymous.ts +++ b/apps/sim/lib/auth/anonymous.ts @@ -103,7 +103,3 @@ export function createAnonymousSession(): AnonymousSession { }, } } - -export function createAnonymousGetSessionResponse(): { data: AnonymousSession } { - return { data: createAnonymousSession() } -}