Skip to content

Commit 0c189dd

Browse files
authored
Expose jose (JWT) validation inner errors (#494)
1 parent 26c596d commit 0c189dd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/olive-colts-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": patch
3+
---
4+
5+
Expose inner JWT verification error causes for better debugging.

src/auth/verify-jwt.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ export const verifyJWT = async ({
3535
debug("Token Claims decoded from jwt");
3636
} catch (e) {
3737
debug("Token Claims could not be decoded from JWT, will respond with Bad Request");
38-
throw new Error(`${ERROR_MESSAGE} Could not decode authorization token.`);
38+
throw new Error(`${ERROR_MESSAGE} Could not decode authorization token.`, {
39+
cause: e,
40+
});
3941
}
4042

4143
try {
4244
verifyTokenExpiration(tokenClaims);
4345
} catch (e) {
44-
throw new Error(`${ERROR_MESSAGE} ${(e as Error).message}`);
46+
throw new Error(`${ERROR_MESSAGE} ${(e as Error).message}`, {
47+
cause: e,
48+
});
4549
}
4650

4751
if (tokenClaims.app !== appId) {
@@ -69,6 +73,8 @@ export const verifyJWT = async ({
6973

7074
console.error(e);
7175

72-
throw new Error(`${ERROR_MESSAGE} JWT signature verification failed.`);
76+
throw new Error(`${ERROR_MESSAGE} JWT signature verification failed.`, {
77+
cause: e,
78+
});
7379
}
7480
};

0 commit comments

Comments
 (0)