Skip to content

Commit bdcb358

Browse files
committed
fix(auth): add refresh token validation and revoked token handling
1 parent 721490d commit bdcb358

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/routes/api/auth.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,22 @@ app.post(
151151
app.post(
152152
'/refresh-token',
153153
[authValidator.refreshToken],
154-
asyncRoute(async (req, res) => {
154+
asyncRoute(async (req, res, next) => {
155155
const { refreshToken } = matchedData(req, { locations: ['body'] });
156+
const findRefreshToken = AuthTokenModel.findOne({
157+
where: { token: refreshToken, type: 'refresh-token' },
158+
});
156159
const { userId } = jwtDecode(refreshToken);
157-
const accessToken = jwtHelper.createUserToken('access-token', userId);
158160

161+
if (!findRefreshToken) {
162+
return next(httpErrors.Unauthorized('Invalid token'));
163+
}
164+
165+
if (findRefreshToken.isRevoked) {
166+
return next(httpErrors.Unauthorized('Token was revoked'));
167+
}
168+
169+
const accessToken = jwtHelper.createUserToken('access-token', userId);
159170
await AuthTokenModel.create({ type: 'access-token', token: accessToken });
160171

161172
// send response

0 commit comments

Comments
 (0)