Skip to content

Commit

Permalink
Merge pull request #12 from eshwinrio/bugfix/KAYA-44-JWT-Expiration-t…
Browse files Browse the repository at this point in the history
…hrows-InternalServerError

bugfix/KAYA-44-JWT-Expiration-throws-InternalServerError
  • Loading branch information
eshwinrio authored Feb 12, 2024
2 parents 0bea62d + aae246a commit 2e2f342
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions auth-server/src/middlewares/require-access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import httpErrors from 'http-errors';
import qs from 'qs';
import { AccessTokenPayload, verifyAccessToken } from '../lib/token.js';
import validator from 'validator';
import jsonwebtoken from 'jsonwebtoken';

type Locals = Record<'accessTokenData', AccessTokenPayload>;
type AccessTokenEnforcer = RequestHandler<ParamsDictionary, any, any, qs.ParsedQs, Locals>;
Expand All @@ -22,6 +23,10 @@ export default function (): AccessTokenEnforcer {
response.locals.accessTokenData = accessTokenData;
next();
} catch (error) {
if (error instanceof jsonwebtoken.TokenExpiredError) {
response.clearCookie('access_token');
return next(httpErrors.Unauthorized('Access token expired'));
}
next(error);
}
};
Expand Down

0 comments on commit 2e2f342

Please sign in to comment.