feat: Add conditional email verification via dynamic Parse Server options verifyUserEmails, sendUserEmailVerification that now accept functions (#8425)

This commit is contained in:
Daniel
2023-06-20 20:10:25 +10:00
committed by GitHub
parent 3710da7379
commit 44acd6d9ed
11 changed files with 341 additions and 82 deletions

View File

@@ -447,7 +447,7 @@ export class UsersRouter extends ClassesRouter {
}
}
handleVerificationEmailRequest(req) {
async handleVerificationEmailRequest(req) {
this._throwOnBadEmailConfig(req);
const { email } = req.body;
@@ -461,25 +461,25 @@ export class UsersRouter extends ClassesRouter {
);
}
return req.config.database.find('_User', { email: email }).then(results => {
if (!results.length || results.length < 1) {
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
}
const user = results[0];
const results = await req.config.database.find('_User', { email: email });
if (!results.length || results.length < 1) {
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
}
const user = results[0];
// remove password field, messes with saving on postgres
delete user.password;
// remove password field, messes with saving on postgres
delete user.password;
if (user.emailVerified) {
throw new Parse.Error(Parse.Error.OTHER_CAUSE, `Email ${email} is already verified.`);
}
if (user.emailVerified) {
throw new Parse.Error(Parse.Error.OTHER_CAUSE, `Email ${email} is already verified.`);
}
const userController = req.config.userController;
return userController.regenerateEmailVerifyToken(user).then(() => {
userController.sendVerificationEmail(user);
return { response: {} };
});
});
const userController = req.config.userController;
const send = await userController.regenerateEmailVerifyToken(user, req.auth.isMaster);
if (send) {
userController.sendVerificationEmail(user, req);
}
return { response: {} };
}
async handleChallenge(req) {