Skip to content

Commit ca382e9

Browse files
committed
Fix: jwt.decode doesn't throw, check null instead
1 parent 00763fa commit ca382e9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,9 @@ export const expressjwt = (options: Params) => {
160160
}
161161
}
162162

163-
let decodedToken: jwt.Jwt;
164-
165-
try {
166-
decodedToken = jwt.decode(token, { complete: true });
167-
} catch (err) {
168-
throw new UnauthorizedError('invalid_token', err);
163+
const decodedToken = jwt.decode(token, { complete: true });
164+
if (!decodedToken) {
165+
throw new UnauthorizedError('invalid_token', { message: 'The token could not be decoded.' });
169166
}
170167

171168
const key = await getVerificationKey(req, decodedToken);

0 commit comments

Comments
 (0)