| // app/api/auth/me/route.ts | |
| import { cookies } from 'next/headers'; | |
| import { NextResponse } from 'next/server'; | |
| export async function GET() { | |
| try { | |
| const cookieStore = await cookies(); | |
| const token = cookieStore.get('auth_token')?.value; | |
| if (!token) { | |
| return NextResponse.json( | |
| { message: 'Not authenticated' }, | |
| { status: 401 } | |
| ); | |
| } | |
| const response = await fetch( | |
| 'https://byteriot-candidateexplorer.hf.space/CandidateExplorer/admin/me', | |
| { | |
| headers: { Authorization: `Bearer ${token}` }, | |
| } | |
| ); | |
| if (!response.ok) { | |
| return NextResponse.json( | |
| { message: 'Invalid token' }, | |
| { status: 401 } | |
| ); | |
| } | |
| const userData = await response.json(); | |
| return NextResponse.json(userData, { status: 200 }); | |
| } catch (error) { | |
| console.error('Get user error:', error); | |
| return NextResponse.json( | |
| { message: 'Failed to get user' }, | |
| { status: 500 } | |
| ); | |
| } | |
| } | |