Files
ember-market-frontend/app/api/auth/check/route.ts
2025-03-23 21:58:51 +00:00

44 lines
1.2 KiB
TypeScript

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 }
);
}
}