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/packages/rocketchat-lib/server/methods/checkUsernameAvailability.js

27 lines
724 B

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
Meteor.methods({
checkUsernameAvailability(username) {
check(username, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUsername' });
}
const user = Meteor.user();
if (user.username && !RocketChat.settings.get('Accounts_AllowUsernameChange')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' });
}
if (user.username === username) {
return true;
}
return RocketChat.checkUsernameAvailability(username);
},
});
RocketChat.RateLimiter.limitMethod('checkUsernameAvailability', 1, 1000, {
userId() { return true; },
});