The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/afterVerifyEmail.js

29 lines
827 B

import { Meteor } from 'meteor/meteor';
import { Users, Roles } from '../../app/models';
Meteor.methods({
afterVerifyEmail() {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'afterVerifyEmail',
});
}
const user = Users.findOneById(userId);
if (user && user.emails && Array.isArray(user.emails)) {
const verifiedEmail = user.emails.find((email) => email.verified);
const rolesToChangeTo = { anonymous: ['user'] };
const rolesThatNeedChanges = user.roles.filter((role) => rolesToChangeTo[role]);
if (rolesThatNeedChanges.length && verifiedEmail) {
rolesThatNeedChanges.forEach((role) => {
Roles.addUserRoles(user._id, rolesToChangeTo[role]);
Roles.removeUserRoles(user._id, role);
});
}
}
},
});