diff --git a/app/api/auth/check/route.ts b/app/api/auth/check/route.ts new file mode 100644 index 0000000..6766ee2 --- /dev/null +++ b/app/api/auth/check/route.ts @@ -0,0 +1,44 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export async function GET(req: NextRequest) { + try { + const token = req.cookies.get('Authorization')?.value; + + if (!token) { + return NextResponse.json( + { error: 'No authorization token found' }, + { status: 401 } + ); + } + + const apiUrl = process.env.SERVER_API_URL || 'https://internal-api.inboxi.ng/api'; + console.log(`Server auth check calling: ${apiUrl}/auth/me`); + + const res = await fetch(`${apiUrl}/auth/me`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + // This is a server component, so we can use Node.js options if needed + // (though we'll avoid for compatibility) + }); + + if (!res.ok) { + return NextResponse.json( + { error: 'Authentication failed' }, + { status: res.status } + ); + } + + const data = await res.json(); + return NextResponse.json(data); + + } catch (error) { + console.error('Auth check error:', error); + return NextResponse.json( + { error: 'Failed to validate authentication' }, + { status: 500 } + ); + } +} \ No newline at end of file