-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathadmin.api.v1.revoked-api-keys.$revokedApiKeyId.ts
More file actions
48 lines (38 loc) · 1.31 KB
/
admin.api.v1.revoked-api-keys.$revokedApiKeyId.ts
File metadata and controls
48 lines (38 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { ActionFunctionArgs, json } from "@remix-run/server-runtime";
import { z } from "zod";
import { prisma } from "~/db.server";
import { requireAdminApiRequest } from "~/services/personalAccessToken.server";
const ParamsSchema = z.object({
revokedApiKeyId: z.string(),
});
const RequestBodySchema = z.object({
expiresAt: z.coerce.date(),
});
export async function action({ request, params }: ActionFunctionArgs) {
await requireAdminApiRequest(request);
const { revokedApiKeyId } = ParamsSchema.parse(params);
const rawBody = await request.json();
const parsedBody = RequestBodySchema.safeParse(rawBody);
if (!parsedBody.success) {
return json({ error: "Invalid request body", issues: parsedBody.error.issues }, { status: 400 });
}
const existing = await prisma.revokedApiKey.findFirst({
where: { id: revokedApiKeyId },
select: { id: true },
});
if (!existing) {
return json({ error: "Revoked API key not found" }, { status: 404 });
}
const updated = await prisma.revokedApiKey.update({
where: { id: revokedApiKeyId },
data: { expiresAt: parsedBody.data.expiresAt },
});
return json({
success: true,
revokedApiKey: {
id: updated.id,
runtimeEnvironmentId: updated.runtimeEnvironmentId,
expiresAt: updated.expiresAt.toISOString(),
},
});
}