Skip to content

Commit

Permalink
Fix: jwt.decode does throw, check null instead
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 6, 2023
1 parent 00763fa commit ef67256
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ef67256

Please sign in to comment.