36 lines
956 B
TypeScript
36 lines
956 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
const response = await fetch('http://aggios-backend:8080/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
const text = await response.text();
|
|
let data: any;
|
|
try {
|
|
data = JSON.parse(text);
|
|
} catch (e) {
|
|
data = { error: text };
|
|
}
|
|
|
|
if (!response.ok) {
|
|
return NextResponse.json(data, { status: response.status });
|
|
}
|
|
|
|
return NextResponse.json(data);
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Erro ao processar login' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|