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

Function GET

web/src/app/api/user/preferences/route.ts:87–121  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

85}
86
87export async function GET(request: NextRequest) {
88 let userId: string | undefined
89
90 // First, try Bearer token authentication (for CLI clients)
91 const apiKey = extractApiKeyFromHeader(request)
92 if (apiKey) {
93 const userIdFromToken = await getUserIdFromSessionToken(apiKey)
94 if (userIdFromToken) {
95 userId = userIdFromToken
96 }
97 }
98
99 // Fall back to NextAuth session authentication (for web clients)
100 if (!userId) {
101 const session = await getServerSession(authOptions)
102 userId = session?.user?.id
103 }
104
105 if (!userId) {
106 return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
107 }
108
109 const user = await db.query.user.findFirst({
110 where: eq(schema.user.id, userId),
111 columns: { fallback_to_a_la_carte: true },
112 })
113
114 if (!user) {
115 return NextResponse.json({ error: 'User not found' }, { status: 404 })
116 }
117
118 return NextResponse.json({
119 fallbackToALaCarte: user.fallback_to_a_la_carte,
120 })
121}

Callers

nothing calls this directly

Calls 2

extractApiKeyFromHeaderFunction · 0.90

Tested by

no test coverage detected