수정
Some checks failed
deploy-on-main / deploy (push) Failing after 22s

This commit is contained in:
koreacomp5
2025-11-09 19:53:42 +09:00
parent 1c2222da67
commit cfbb3d50ee
12 changed files with 289 additions and 153 deletions

View File

@@ -35,17 +35,42 @@ export async function POST(req: Request) {
if (!user || !user.passwordHash || !verifyPassword(password, user.passwordHash)) {
return NextResponse.json({ error: "아이디 또는 비밀번호가 올바르지 않습니다" }, { status: 401 });
}
// 사용자의 관리자 권한 여부 확인
let isAdmin = false;
const userRoles = await prisma.userRole.findMany({
where: { userId: user.userId },
select: { roleId: true },
});
if (userRoles.length > 0) {
const roleIds = userRoles.map((r) => r.roleId);
const hasAdmin = await prisma.rolePermission.findFirst({
where: {
roleId: { in: roleIds },
resource: "ADMIN",
action: "ADMINISTER",
allowed: true,
},
select: { id: true },
});
isAdmin = !!hasAdmin;
}
const res = NextResponse.json({ ok: true, user: { userId: user.userId, nickname: user.nickname } });
res.headers.append(
"Set-Cookie",
`uid=${encodeURIComponent(user.userId)}; Path=/; HttpOnly; SameSite=Lax`
);
res.headers.append(
"Set-Cookie",
`isAdmin=${isAdmin ? "1" : "0"}; Path=/; HttpOnly; SameSite=Lax`
);
return res;
}
export async function DELETE() {
const res = NextResponse.json({ ok: true });
res.headers.append("Set-Cookie", `uid=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax`);
res.headers.append("Set-Cookie", `isAdmin=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax`);
return res;
}