fix: convert policyId to Int before Prisma insert in create_new_token
The wire-level `create_new_token` RPC carries `policyId` as a string
(everything in NDK RPC params is string). The handler correctly
parseInts it for the `findUnique({where:{id:parseInt(policyId)}})` call
but then forwards the unparsed string straight into the Prisma
`token.create({data:{...policyId}})` payload. Prisma rejects with
"Argument `policyId`: Invalid value provided. Expected Int or Null,
provided String" because `Token.policyId` is declared `Int` per the
schema (references `Policy.id`, which is autoincrement Int).
Hoist `policyIdInt = parseInt(policyId)` and use it for both the
findUnique lookup and the create payload. Latent upstream bug — no one
would have seen it before because the wrong-kind error response (fixed
in the previous commit) made the symptom look like a transport timeout
rather than a Prisma validation error.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0a510b7f9a
commit
5e77de1202
1 changed files with 6 additions and 2 deletions
|
|
@ -7,15 +7,19 @@ export default async function createNewToken(admin: AdminInterface, req: NDKRpcR
|
||||||
|
|
||||||
if (!clientName || !policyId) throw new Error("Invalid params");
|
if (!clientName || !policyId) throw new Error("Invalid params");
|
||||||
|
|
||||||
const policy = await prisma.policy.findUnique({ where: { id: parseInt(policyId) }, include: { rules: true } });
|
const policyIdInt = parseInt(policyId);
|
||||||
|
const policy = await prisma.policy.findUnique({ where: { id: policyIdInt }, include: { rules: true } });
|
||||||
|
|
||||||
if (!policy) throw new Error("Policy not found");
|
if (!policy) throw new Error("Policy not found");
|
||||||
|
|
||||||
console.log({clientName, policy, durationInHours});
|
console.log({clientName, policy, durationInHours});
|
||||||
|
|
||||||
const token = [...Array(64)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
const token = [...Array(64)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
||||||
|
// policyId must be Int per the Prisma schema (Token.policyId references
|
||||||
|
// Policy.id which is autoincrement Int). Upstream passes the raw string
|
||||||
|
// from the wire — caught during aiolabs/nsecbunkerd#7 diagnosis 2026-05-27.
|
||||||
const data: any = {
|
const data: any = {
|
||||||
keyName, clientName, policyId,
|
keyName, clientName, policyId: policyIdInt,
|
||||||
createdBy: req.pubkey,
|
createdBy: req.pubkey,
|
||||||
token
|
token
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue