Skip to content

Commit

Permalink
Return 401 status when JWT validation fails (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Jan 31, 2024
2 parents 80ea828 + 7587ca9 commit 90ced55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tough-swans-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"postgraphile": patch
---

PgLazyJWTPreset: return 401 error when validation of JWT fails.
7 changes: 6 additions & 1 deletion postgraphile/postgraphile/src/presets/lazy-jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ const GrafservPgJWTPlugin: GraphileConfig.Plugin = {
},
(err, claims) => {
if (err) {
(err as any).statusCode = 401;
reject(err);
} else if (!claims || typeof claims === "string") {
reject(new Error("Invalid JWT payload"));
reject(
Object.assign(new Error("Invalid JWT payload"), {
statusCode: 401,
}),
);
} else {
resolve(claims);
}
Expand Down

0 comments on commit 90ced55

Please sign in to comment.