From ca382e9c1f019fc0073d7db689a46f345b124578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 6 Feb 2023 18:44:39 +0200 Subject: [PATCH] Fix: jwt.decode doesn't throw, check null instead --- src/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7758f4b8..be39dde6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -160,12 +160,9 @@ export const expressjwt = (options: Params) => { } } - let decodedToken: jwt.Jwt; - - try { - decodedToken = jwt.decode(token, { complete: true }); - } catch (err) { - throw new UnauthorizedError('invalid_token', err); + const decodedToken = jwt.decode(token, { complete: true }); + if (!decodedToken) { + throw new UnauthorizedError('invalid_token', { message: 'The token could not be decoded.' }); } const key = await getVerificationKey(req, decodedToken);