( req: NextRequest, deps: FreebuffSessionDeps, )
| 151 | | { userId: string; userEmail: string | null; userBanned: boolean } |
| 152 | |
| 153 | async 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 | |
| 189 | function serverError( |
| 190 | deps: FreebuffSessionDeps, |
no test coverage detected