Allaning:roles is depreciated?

Hi guys, after i upgrade my version of meteor for 1.9 i have this issue.

Error: Role ‘ROLE_MASTER_ADMIN’ does not exist.
W20200306-08:40:53.337(-3)? (STDERR) at Object._addUserToRole (packages/alanning:roles/roles/roles_common.js:473:15)

here is my code.
import moment from ‘moment’;

import { Company, ScheduleExecutedJobs } from ‘/lib/collections’;

import {

ROLE_MASTER_ADMIN,

ROLE_ADMIN,

ROLE_USER,

ROLE_WS_MASTER_ADMIN,

GROUP_MASTER_ADMIN,

GROUP_WS

} from ‘/lib/constants/role_constants’;

import { createJobUpdateStatusMonitor } from ‘…/job/functions/default_job.js’;

export default function () {

if(Meteor.users.find({}).count() == 0){

let lastName = "Admin";

let firstName = "Administrator";

//const birthday = moment.utc().unix() * 1000;

let email = "contato@roiiiot.com.br";

let password = "superhyo";

  console.log(email);

  Accounts.createUser({

    username: email,

    controlId: 1,

    email: email,

    password: password,

    active: true,

    profile: {

      person: {

         firstName: firstName,

         lastName: lastName,

         email: email,

         birthday: new Date(),

        device: '00:00:00:00:00'

      }

   }

  });

  const user = Meteor.users.find({username: email}).fetch();

  console.log(user);

  const userId = user[0]._id;

  console.log(ROLE_MASTER_ADMIN);

  

  Roles.addUsersToRoles(userId, ROLE_MASTER_ADMIN, GROUP_MASTER_ADMIN);

  console.log(user.Roles);

    

firstName = "RestAccess";

lastName = "";

email = "wsadmin@roiiiot.com.br";

password = "restadmin12345";

Accounts.createUser({

  username: email,

  controlId: 2,

  email: email,

  password: password,

  active: true,

  profile: {

    person: {

       firstName: firstName,

       lastName: lastName,

       email: email,

       birthday: new Date()

    }

}

});

const user2 = Meteor.users.find({username: email}).fetch();

console.log(user2);

const userId2 = user2[0]._id;

Roles.addUsersToRoles(userId2, ROLE_WS_MASTER_ADMIN, GROUP_WS);

}

//Cria job Status monitor

createJobUpdateStatusMonitor();

}

Have you checked if your version of alanning:roles has been updated to the new version, which requires a migration of data?

1 Like

I follow this steps now but i have this issue.

Uncaught TypeError: Cannot read property ‘Roles’ of undefined
at packages/shell-server/shell-server.js:249:21
at runBound (domain.js:439:12)
at bound (domain.js:426:14)
at defaultEval (repl.js:430:29)
at Script.runInThisContext (vm.js:120:20)
at repl:1:-36