MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / GET

Function GET

web/src/app/api/user/profile/route.ts:13–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import { logger } from '@/util/logger'
12
13export async function GET() {
14 const session = await getServerSession(authOptions)
15
16 if (!session?.user?.id) {
17 return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
18 }
19
20 try {
21 const user = await db.query.user.findFirst({
22 where: eq(schema.user.id, session.user.id),
23 columns: {
24 handle: true,
25 auto_topup_enabled: true,
26 auto_topup_threshold: true,
27 auto_topup_amount: true,
28 created_at: true,
29 },
30 })
31
32 if (!user) {
33 return NextResponse.json({ error: 'User not found' }, { status: 404 })
34 }
35
36 const { blockedReason: auto_topup_blocked_reason } =
37 await validateAutoTopupStatus({ userId: session.user.id, logger })
38
39 const response: Partial<UserProfile> = {
40 handle: user.handle,
41 auto_topup_enabled: user.auto_topup_enabled && !auto_topup_blocked_reason,
42 auto_topup_threshold: user.auto_topup_threshold ?? 500,
43 auto_topup_amount: user.auto_topup_amount ?? 2000,
44 auto_topup_blocked_reason,
45 created_at: user.created_at,
46 }
47
48 return NextResponse.json(response)
49 } catch (error) {
50 logger.error(
51 { error, userId: session.user.id },
52 'Error fetching user profile',
53 )
54 return NextResponse.json(
55 { error: 'Internal Server Error' },
56 { status: 500 },
57 )
58 }
59}

Callers

nothing calls this directly

Calls 1

validateAutoTopupStatusFunction · 0.90

Tested by

no test coverage detected