Skip to content

Commit

Permalink
feat(server): add quarantine check for user login tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
chimpdev committed Jan 14, 2025
1 parent b9b4be4 commit a409afb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const morgan = require('morgan');

const sleep = require('@/utils/sleep');
const User = require('@/schemas/User');
const findQuarantineEntry = require('@/utils/findQuarantineEntry');

module.exports = class Server {
constructor() {
Expand Down Expand Up @@ -110,6 +111,9 @@ module.exports = class Server {

if (decoded.iat < Math.floor(new Date(user.lastLogoutAt).getTime() / 1000)) throw new Error('Token expired.');

const userQuarantined = await findQuarantineEntry.single('USER_ID', user.id, 'LOGIN').catch(() => false);
if (userQuarantined) throw new Error('User that this token belongs to is not allowed to login, so the token is invalid.');

request.user = {
id: decoded.payload.sub
};
Expand Down

0 comments on commit a409afb

Please sign in to comment.