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 <theo@sim.ai>

* 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 <walif6@gmail.com>
Co-authored-by: Theodore Li <theodoreqili@gmail.com>
Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: Theodore Li <theo@sim.ai>
This commit is contained in:
Alan Daniel
2026-05-04 16:28:18 -07:00
committed by GitHub
co-authored by Theodore Li Waleed Theodore Li Siddharth Ganesan Vikhyath Mondreti
parent 029ac9fb05
commit 1dc6f7dd09
3 changed files with 8 additions and 16 deletions
+6 -10
View File
@@ -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' },
})
})
+2 -2
View File
@@ -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)
-4
View File
@@ -103,7 +103,3 @@ export function createAnonymousSession(): AnonymousSession {
},
}
}
export function createAnonymousGetSessionResponse(): { data: AnonymousSession } {
return { data: createAnonymousSession() }
}