Add login and register dialogs, user dropdown menu with profile link and logout option, and integrate with session management hook. Prevent hydration mismatches by conditionally rendering auth elements after mount. Update package-lock.json with new @esbuild dependencies for build tooling.
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { secureLogger } from "@/lib/secure-logger";
|
|
import { getUserById } from "@/lib/db/queries/users";
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { id } = await params;
|
|
const userId = parseInt(id, 10);
|
|
|
|
if (isNaN(userId)) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: "ID de usuário inválido",
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const user = await getUserById(userId);
|
|
|
|
if (!user) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: "Usuário não encontrado",
|
|
},
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
// Retornar apenas dados públicos (sem informações sensíveis)
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
user: {
|
|
userId: user.user_id,
|
|
username: user.username,
|
|
firstName: user.first_name,
|
|
lastName: user.last_name,
|
|
accountLevel: user.account_level,
|
|
hasDonated: user.has_donated,
|
|
createdAt: user.created_at,
|
|
},
|
|
},
|
|
{ status: 200 }
|
|
);
|
|
} catch (error) {
|
|
secureLogger.error("❌ Erro ao buscar perfil público", {
|
|
error: error instanceof Error ? error.message : "Erro desconhecido",
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
timestamp: new Date().toISOString(),
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : "Erro interno",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|