Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Throw when an inactive user is found
Browse files Browse the repository at this point in the history
  • Loading branch information
solocommand committed Nov 18, 2024
1 parent b657288 commit 1e4377d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions services/graphql-server/src/user/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const { AuthenticationError } = require('apollo-server-express');
const bcrypt = require('bcryptjs');
const TokenService = require('./token-service');

const activeCriteria = {
accountNonExpired: true,
accountNonLocked: true,
credentialsNonExpired: true,
enabled: true,
};

const UserService = class UserService {
constructor({ basedb }) {
this.basedb = basedb;
Expand All @@ -11,10 +18,7 @@ const UserService = class UserService {
async login(username, plaintext) {
const criteria = {
username,
accountNonExpired: true,
accountNonLocked: true,
credentialsNonExpired: true,
enabled: true,
...activeCriteria,
};
const user = await this.basedb.findOne('platform.User', criteria);
if (!user || !user.password) throw new AuthenticationError('The provided user credentials are invalid.');
Expand All @@ -32,7 +36,10 @@ const UserService = class UserService {

async checkAuth(token) {
const { uid } = await this.tokenService.validate(token);
return this.basedb.findOne('platform.User', { _id: uid });
return this.basedb.strictFindOne('platform.User', {
_id: uid,
...activeCriteria,
});
}
};

Expand Down

0 comments on commit 1e4377d

Please sign in to comment.