Skip to content

Commit 1dc6f7d

Browse files
stylesshwaleedlatif1TheodoreSpeaksSg312icecrasher321
authored
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>
1 parent 029ac9f commit 1dc6f7d

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

apps/sim/app/api/auth/[...all]/route.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ const handlerMocks = vi.hoisted(() => ({
88
betterAuthGET: vi.fn(),
99
betterAuthPOST: vi.fn(),
1010
ensureAnonymousUserExists: vi.fn(),
11-
createAnonymousGetSessionResponse: vi.fn(() => ({
12-
data: {
13-
user: { id: 'anon' },
14-
session: { id: 'anon-session' },
15-
},
11+
createAnonymousSession: vi.fn(() => ({
12+
user: { id: 'anon' },
13+
session: { id: 'anon-session' },
1614
})),
1715
isAuthDisabled: false,
1816
}))
@@ -30,7 +28,7 @@ vi.mock('@/lib/auth', () => ({
3028

3129
vi.mock('@/lib/auth/anonymous', () => ({
3230
ensureAnonymousUserExists: handlerMocks.ensureAnonymousUserExists,
33-
createAnonymousGetSessionResponse: handlerMocks.createAnonymousGetSessionResponse,
31+
createAnonymousSession: handlerMocks.createAnonymousSession,
3432
}))
3533

3634
vi.mock('@/lib/core/config/feature-flags', () => ({
@@ -63,10 +61,8 @@ describe('auth catch-all route (DISABLE_AUTH get-session)', () => {
6361
expect(handlerMocks.ensureAnonymousUserExists).toHaveBeenCalledTimes(1)
6462
expect(handlerMocks.betterAuthGET).not.toHaveBeenCalled()
6563
expect(json).toEqual({
66-
data: {
67-
user: { id: 'anon' },
68-
session: { id: 'anon-session' },
69-
},
64+
user: { id: 'anon' },
65+
session: { id: 'anon-session' },
7066
})
7167
})
7268

apps/sim/app/api/auth/[...all]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { toNextJsHandler } from 'better-auth/next-js'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { auth } from '@/lib/auth'
4-
import { createAnonymousGetSessionResponse, ensureAnonymousUserExists } from '@/lib/auth/anonymous'
4+
import { createAnonymousSession, ensureAnonymousUserExists } from '@/lib/auth/anonymous'
55
import { isAuthDisabled } from '@/lib/core/config/feature-flags'
66
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
77

@@ -24,7 +24,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
2424

2525
if (path === 'get-session' && isAuthDisabled) {
2626
await ensureAnonymousUserExists()
27-
return NextResponse.json(createAnonymousGetSessionResponse())
27+
return NextResponse.json(createAnonymousSession())
2828
}
2929

3030
return betterAuthGET(request)

apps/sim/lib/auth/anonymous.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,3 @@ export function createAnonymousSession(): AnonymousSession {
103103
},
104104
}
105105
}
106-
107-
export function createAnonymousGetSessionResponse(): { data: AnonymousSession } {
108-
return { data: createAnonymousSession() }
109-
}

0 commit comments

Comments
 (0)