mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Squashed commit of the following:
commit 22971a0c0bd1c25e147fdc9d662fd55ca522193b Author: SabreCat <sabe@habitica.com> Date: Fri Aug 18 21:13:49 2023 -0500 fix(auth): don't mix include/exclude commit efbb8fa136587a4c781660246cb426968cfe108a Author: SabreCat <sabe@habitica.com> Date: Fri Aug 18 20:51:30 2023 -0500 refactor(auth): remove unneeded query field
This commit is contained in:
@@ -65,18 +65,22 @@ export function authWithHeaders (options = {}) {
|
|||||||
return next(new NotAuthorized(res.t('missingAuthHeaders')));
|
return next(new NotAuthorized(res.t('missingAuthHeaders')));
|
||||||
}
|
}
|
||||||
|
|
||||||
const userQuery = {
|
const userQuery = { _id: userId };
|
||||||
_id: userId,
|
|
||||||
apiToken,
|
let fields = getUserFields(options, req);
|
||||||
};
|
// If the request didn't include the API Token, retrieve it for validation
|
||||||
|
if (fields && fields.indexOf('apiToken') === -1 && fields.indexOf('-') === -1) {
|
||||||
|
fields = `${fields} apiToken`;
|
||||||
|
}
|
||||||
|
|
||||||
const fields = getUserFields(options, req);
|
|
||||||
const findPromise = fields ? User.findOne(userQuery).select(fields) : User.findOne(userQuery);
|
const findPromise = fields ? User.findOne(userQuery).select(fields) : User.findOne(userQuery);
|
||||||
|
|
||||||
return findPromise
|
return findPromise
|
||||||
.exec()
|
.exec()
|
||||||
.then(user => {
|
.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) {
|
if (user.auth.blocked) {
|
||||||
// We want the accountSuspended message to be translated but the language
|
// We want the accountSuspended message to be translated but the language
|
||||||
|
|||||||
Reference in New Issue
Block a user