mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
use throw instead of returning next inside of promises
This commit is contained in:
@@ -149,7 +149,7 @@ api.loginLocal = {
|
|||||||
// TODO place back long error message return res.json(401, {err:"Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click \"Forgot Password\"."});
|
// TODO place back long error message return res.json(401, {err:"Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click \"Forgot Password\"."});
|
||||||
let isValidPassword = user && user.auth.local.hashed_password !== passwordUtils.encrypt(req.body.password, user.auth.local.salt);
|
let isValidPassword = user && user.auth.local.hashed_password !== passwordUtils.encrypt(req.body.password, user.auth.local.salt);
|
||||||
|
|
||||||
if (!isValidPassword) return next(new NotAuthorized(res.t('invalidLoginCredentials')));
|
if (!isValidPassword) throw new NotAuthorized(res.t('invalidLoginCredentials'));
|
||||||
_loginRes(user, ...arguments);
|
_loginRes(user, ...arguments);
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
@@ -195,6 +195,7 @@ api.loginSocial = {
|
|||||||
if (savedUser.auth[network].emails && savedUser.auth.facebook.emails[0] && savedUser.auth[network].emails[0].value) {
|
if (savedUser.auth[network].emails && savedUser.auth.facebook.emails[0] && savedUser.auth[network].emails[0].value) {
|
||||||
EmailUnsubscription
|
EmailUnsubscription
|
||||||
.remove({email: savedUser.auth[network].emails[0].value.toLowerCase()})
|
.remove({email: savedUser.auth[network].emails[0].value.toLowerCase()})
|
||||||
|
.exec()
|
||||||
.then(() => sendTxnEmail(savedUser, 'welcome')); // eslint-disable-line max-nested-callbacks
|
.then(() => sendTxnEmail(savedUser, 'welcome')); // eslint-disable-line max-nested-callbacks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ export function authWithHeaders (req, res, next) {
|
|||||||
})
|
})
|
||||||
.exec()
|
.exec()
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
if (!user) return next(new NotAuthorized(i18n.t('invalidCredentials')));
|
if (!user) throw new NotAuthorized(i18n.t('invalidCredentials'));
|
||||||
if (user.auth.blocked) return next(new NotAuthorized(i18n.t('accountSuspended', {userId: user._id})));
|
if (user.auth.blocked) throw new NotAuthorized(i18n.t('accountSuspended', {userId: user._id}));
|
||||||
|
|
||||||
res.locals.user = user;
|
res.locals.user = user;
|
||||||
// TODO use either session/cookie or headers, not both
|
// TODO use either session/cookie or headers, not both
|
||||||
req.session.userId = user._id;
|
req.session.userId = user._id;
|
||||||
return next();
|
next();
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ export function authWithSession (req, res, next) {
|
|||||||
})
|
})
|
||||||
.exec()
|
.exec()
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
if (!user) return next(new NotAuthorized(i18n.t('invalidCredentials')));
|
if (!user) throw new NotAuthorized(i18n.t('invalidCredentials'));
|
||||||
|
|
||||||
res.locals.user = user;
|
res.locals.user = user;
|
||||||
return next();
|
next();
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user