Files

49 lines
1.5 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
try {
const token = request.headers.get('Authorization')?.replace('Bearer ', '');
if (!token) {
return NextResponse.json(
{ error: 'Token não fornecido' },
{ status: 401 }
);
}
const body = await request.json();
if (!body.current_password || !body.new_password) {
return NextResponse.json(
{ error: 'Senha atual e nova senha são obrigatórias' },
{ status: 400 }
);
}
const response = await fetch('http://aggios-backend:8080/api/portal/change-password', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
if (!response.ok) {
const errorData = await response.json();
return NextResponse.json(
{ error: errorData.error || 'Erro ao alterar senha' },
{ status: response.status }
);
}
return NextResponse.json({ message: 'Senha alterada com sucesso' });
} catch (error) {
console.error('Change password error:', error);
return NextResponse.json(
{ error: 'Erro ao alterar senha' },
{ status: 500 }
);
}
}