MCPcopy
hub / github.com/CodebuffAI/codebuff / resolveUser

Function resolveUser

web/src/app/api/v1/freebuff/session/_handlers.ts:153–187  ·  view source on GitHub ↗
(
  req: NextRequest,
  deps: FreebuffSessionDeps,
)

Source from the content-addressed store, hash-verified

151 | { userId: string; userEmail: string | null; userBanned: boolean }
152
153async function resolveUser(
154 req: NextRequest,
155 deps: FreebuffSessionDeps,
156): Promise<AuthResult> {
157 const apiKey = extractApiKeyFromHeader(req)
158 if (!apiKey) {
159 return {
160 error: NextResponse.json(
161 {
162 error: 'unauthorized',
163 message: 'Missing or invalid Authorization header',
164 },
165 { status: 401 },
166 ),
167 }
168 }
169 const userInfo = await deps.getUserInfoFromApiKey({
170 apiKey,
171 fields: ['id', 'email', 'banned'],
172 logger: deps.logger,
173 })
174 if (!userInfo?.id) {
175 return {
176 error: NextResponse.json(
177 { error: 'unauthorized', message: 'Invalid API key' },
178 { status: 401 },
179 ),
180 }
181 }
182 return {
183 userId: String(userInfo.id),
184 userEmail: userInfo.email ?? null,
185 userBanned: Boolean(userInfo.banned),
186 }
187}
188
189function serverError(
190 deps: FreebuffSessionDeps,

Callers 3

postFreebuffSessionFunction · 0.85
getFreebuffSessionFunction · 0.85
deleteFreebuffSessionFunction · 0.85

Calls 1

extractApiKeyFromHeaderFunction · 0.90

Tested by

no test coverage detected