Skip to content

Commit

Permalink
Merge branch 'sabrecat/auth-performance' into delta
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreCat committed Aug 19, 2023
2 parents 201e937 + efbb8fa commit 8d6d433
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions website/server/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ export function authWithHeaders (options = {}) {
return next(new NotAuthorized(res.t('missingAuthHeaders')));
}

const userQuery = {
_id: userId,
apiToken,
};
const userQuery = { _id: userId };

let fields = getUserFields(options, req);
if (fields && fields.indexOf('apiToken') === -1) {
fields = `${fields} apiToken`;
}

const fields = getUserFields(options, req);
const findPromise = fields ? User.findOne(userQuery).select(fields) : User.findOne(userQuery);

return findPromise
.exec()
.then(user => {
if (!user) throw new NotAuthorized(res.t('invalidCredentials'));
if (!user || apiToken !== user.apiToken) {
throw new NotAuthorized(res.t('invalidCredentials'));
}

if (user.auth.blocked) {
// We want the accountSuspended message to be translated but the language
Expand Down

0 comments on commit 8d6d433

Please sign in to comment.