Skip to content

Commit bd94f87

Browse files
committed
fix: audit cursor pagination direction, prevent duplicate service account names
1 parent 0304b17 commit bd94f87

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/app/api/v1/audit/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const GET = apiRoute("audit.read", async (req: NextRequest, ctx) => {
3333
select: { id: true, name: true, email: true },
3434
},
3535
},
36-
orderBy: { createdAt: "desc" },
36+
orderBy: { createdAt: "asc" },
3737
take: limit + 1,
3838
...(after ? { cursor: { id: after }, skip: 1 } : {}),
3939
});

src/server/routers/service-account.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ export const serviceAccountRouter = router({
6363
throw new TRPCError({ code: "UNAUTHORIZED" });
6464
}
6565

66+
const existing = await prisma.serviceAccount.findFirst({
67+
where: { environmentId: input.environmentId, name: input.name },
68+
});
69+
if (existing) {
70+
throw new TRPCError({
71+
code: "CONFLICT",
72+
message:
73+
"A service account with this name already exists in this environment",
74+
});
75+
}
76+
6677
const rawKey = `vf_live_${crypto.randomBytes(24).toString("hex")}`;
6778
const hashedKey = crypto
6879
.createHash("sha256")

0 commit comments

Comments
 (0)