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/app/lib/server/methods/createToken.js

19 lines
618 B

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { hasPermission } from '../../../authorization';
Meteor.methods({
createToken(userId) {
if (!['yes', 'true'].includes(process.env.CREATE_TOKENS_FOR_USERS) || (Meteor.userId() !== userId && !hasPermission(Meteor.userId(), 'user-generate-access-token'))) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'createToken' });
}
const token = Accounts._generateStampedLoginToken();
Accounts._insertLoginToken(userId, token);
return {
userId,
authToken: token.token,
};
},
});