Spaces:
Running
Running
| import { NextRequest, NextResponse } from 'next/server'; | |
| import { requireBasicAuth, createUnauthorizedResponse } from '@/lib/auth'; | |
| /** | |
| * GET /api/auth/me | |
| * Returns current user info including session role | |
| * Used by admin UI to check access permissions | |
| */ | |
| export async function GET(request: NextRequest) { | |
| try { | |
| const auth = await requireBasicAuth(request); | |
| return NextResponse.json({ | |
| userId: auth.userId, | |
| username: auth.username, | |
| sessionRole: auth.sessionRole, | |
| }); | |
| } catch (error) { | |
| if (error instanceof Error && error.message === 'Unauthorized') { | |
| return createUnauthorizedResponse(); | |
| } | |
| console.error('[GET /api/auth/me] Error:', error); | |
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); | |
| } | |
| } | |