Skip to content

Commit f65a924

Browse files
committed
fix: delete web sessions on CLI logout; refactor onboarding/auth
1 parent dc26760 commit f65a924

File tree

13 files changed

+1136
-262
lines changed

13 files changed

+1136
-262
lines changed

web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { DrizzleAdapter } from '@auth/drizzle-adapter'
22
import { processAndGrantCredit } from '@codebuff/billing'
33
import { trackEvent } from '@codebuff/common/analytics'
44
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
5-
import { DEFAULT_FREE_CREDITS_GRANT } from '@codebuff/common/old-constants'
5+
import {
6+
DEFAULT_FREE_CREDITS_GRANT,
7+
SESSION_MAX_AGE_SECONDS,
8+
} from '@codebuff/common/old-constants'
69
import { getNextQuotaReset } from '@codebuff/common/util/dates'
710
import { generateCompactId } from '@codebuff/common/util/string'
811
import { loops } from '@codebuff/internal'
@@ -143,7 +146,7 @@ export const authOptions: NextAuthOptions = {
143146
],
144147
session: {
145148
strategy: 'database',
146-
maxAge: 30 * 24 * 60 * 60, // 30 days
149+
maxAge: SESSION_MAX_AGE_SECONDS,
147150
},
148151
callbacks: {
149152
async session({ session, user }) {

web/src/app/api/auth/cli/code/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export async function POST(req: Request) {
1313
fingerprintId: z.string(),
1414
referralCode: z.string().optional(),
1515
})
16-
const result = reqSchema.safeParse(await req.json())
16+
const requestBody = await req.json()
17+
const result = reqSchema.safeParse(requestBody)
1718
if (!result.success) {
1819
return NextResponse.json({ error: 'Invalid request body' }, { status: 400 })
1920
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, expect, test } from 'bun:test'
2+
3+
import { shouldUnclaim } from '../_helpers'
4+
5+
describe('logout/_helpers', () => {
6+
describe('shouldUnclaim', () => {
7+
describe('when fingerprintMatchFound is true', () => {
8+
test('returns true regardless of hash values', () => {
9+
expect(shouldUnclaim(true, 'stored-hash', 'provided-hash')).toBe(true)
10+
expect(shouldUnclaim(true, null, 'provided-hash')).toBe(true)
11+
expect(shouldUnclaim(true, undefined, 'provided-hash')).toBe(true)
12+
expect(shouldUnclaim(true, 'any-hash', 'different-hash')).toBe(true)
13+
})
14+
})
15+
16+
describe('when fingerprintMatchFound is false', () => {
17+
test('returns true when stored hash matches provided hash', () => {
18+
expect(shouldUnclaim(false, 'matching-hash', 'matching-hash')).toBe(true)
19+
})
20+
21+
test('returns false when stored hash does not match provided hash', () => {
22+
expect(shouldUnclaim(false, 'stored-hash', 'different-hash')).toBe(false)
23+
})
24+
25+
test('returns false when stored hash is null', () => {
26+
expect(shouldUnclaim(false, null, 'provided-hash')).toBe(false)
27+
})
28+
29+
test('returns false when stored hash is undefined', () => {
30+
expect(shouldUnclaim(false, undefined, 'provided-hash')).toBe(false)
31+
})
32+
33+
test('returns false when stored hash is empty string but provided is not', () => {
34+
expect(shouldUnclaim(false, '', 'provided-hash')).toBe(false)
35+
})
36+
37+
test('returns true when both hashes are empty strings', () => {
38+
expect(shouldUnclaim(false, '', '')).toBe(true)
39+
})
40+
})
41+
})
42+
})

0 commit comments

Comments
 (0)