Skip to content

Commit bd30727

Browse files
authored
better keypair auth error message (#913)
1 parent 357c402 commit bd30727

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/server/middleware/auth.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,12 @@ const handleKeypairAuth = async (args: {
331331
}) as jsonwebtoken.JwtPayload;
332332

333333
// If `bodyHash` is provided, it must match a hash of the POST request body.
334-
if (
335-
req.method === "POST" &&
336-
payload?.bodyHash &&
337-
payload.bodyHash !== hashRequestBody(req)
338-
) {
339-
error =
340-
"The request body does not match the hash in the access token. See: https://portal.thirdweb.com/engine/features/keypair-authentication";
341-
throw error;
334+
if (req.method === "POST" && payload?.bodyHash) {
335+
const computedBodyHash = hashRequestBody(req);
336+
if (computedBodyHash !== payload.bodyHash) {
337+
error = `The request body does not match the hash in the access token. See: https://portal.thirdweb.com/engine/v2/features/keypair-authentication. [hash in access token: ${payload.bodyHash}, hash computed from request: ${computedBodyHash}]`;
338+
throw error;
339+
}
342340
}
343341

344342
const { isAllowed, ip } = await checkIpInAllowlist(req);

0 commit comments

Comments
 (0)