fix: Conditional email verification not working in some cases if verifyUserEmails, preventLoginWithUnverifiedEmail set to functions (#8838)
This commit is contained in:
@@ -126,7 +126,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
const accountLockoutPolicy = new AccountLockout(user, req.config);
|
||||
return accountLockoutPolicy.handleLoginAttempt(isValidPassword);
|
||||
})
|
||||
.then(() => {
|
||||
.then(async () => {
|
||||
if (!isValidPassword) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
@@ -137,11 +137,18 @@ export class UsersRouter extends ClassesRouter {
|
||||
if (!req.auth.isMaster && user.ACL && Object.keys(user.ACL).length == 0) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
if (
|
||||
req.config.verifyUserEmails &&
|
||||
req.config.preventLoginWithUnverifiedEmail &&
|
||||
!user.emailVerified
|
||||
) {
|
||||
// Create request object for verification functions
|
||||
const request = {
|
||||
master: req.auth.isMaster,
|
||||
ip: req.config.ip,
|
||||
installationId: req.auth.installationId,
|
||||
};
|
||||
// Get verification conditions which can be booleans or functions; the purpose of this async/await
|
||||
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
|
||||
// conditional statement below, as a developer may decide to execute expensive operations in them
|
||||
const verifyUserEmails = async () => req.config.verifyUserEmails === true || (typeof req.config.verifyUserEmails === 'function' && await Promise.resolve(req.config.verifyUserEmails(request)) === true);
|
||||
const preventLoginWithUnverifiedEmail = async () => req.config.preventLoginWithUnverifiedEmail === true || (typeof req.config.preventLoginWithUnverifiedEmail === 'function' && await Promise.resolve(req.config.preventLoginWithUnverifiedEmail(request)) === true);
|
||||
if (await verifyUserEmails() && await preventLoginWithUnverifiedEmail() && !user.emailVerified) {
|
||||
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, 'User email is not verified.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user