Blame view

imports/startup/server/fixtures.js 796 Bytes
cac7cbc73   tmcdeveloper   4.1.0 release
1
2
3
  import { Meteor } from 'meteor/meteor';
  import { Roles } from 'meteor/alanning:roles';
  import { Accounts } from 'meteor/accounts-base';
1850fc25b   Michel Floyd   Prevent setting u...
4
5
6
7
8
9
10
11
12
13
14
15
  /* Create a default admin user but *only in non-production environments!*
   * This is to avoid a base app being deployed in production with a known generic admin user
   */
  if ( !Meteor.isProduction ) {
    const users = [{
      email: 'admin@admin.com',
      password: 'password',
      profile: {
        name: {first: 'Carl', last: 'Winslow'},
      },
      roles: ['admin'],
    }];
2b1ad7917   tmcdeveloper   wip moving to Met...
16

1850fc25b   Michel Floyd   Prevent setting u...
17
18
    users.forEach(({ email, password, profile, roles }) => {
      const userExists = Meteor.users.findOne({ 'emails.address': email });
2b1ad7917   tmcdeveloper   wip moving to Met...
19

1850fc25b   Michel Floyd   Prevent setting u...
20
21
22
23
24
25
      if (!userExists) {
        const userId = Accounts.createUser({ email, password, profile });
        Roles.addUsersToRoles(userId, roles);
      }
    });
  }