3

I have been working on extending the Meteor.users schema which work fine but after I create the first user in a Meteor.startup() and tried logging in I get a "User Not Found" error. Even though i can see the user in the mongo shell. Here is my schema:

    Schemas.User = new SimpleSchema({
    username: {
        type: String,
        optional: true
    },
    emails: {
        type: Array,
        optional: true
    },
    "emails.$": {
        type: Object
    },
    "emails.$.address": {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    "emails.$.verified": {
        type: Boolean
    },
    createdAt: {
        type: Date,
        optional: true
    },
    "firstName":{
     type: String,
     max: 50,
     min:2
     },
    'middleName':{
    type: String,
    optional: true,
    max: 50
    },
    "lastName":{
     type: String,
     max: 50,
     min:2
    },
    "gender": {
    type: String,
    autoform: {
      afFieldInput: {type: "select-radio-inline",},
      options: 
      [
         {label: "Male", value: "Male"},
         {label: "Female", value: "Female"}

      ]
    }
    },
   "branch": {
      type: String,
      optional: true,
      autoform: {
        type: "select",
        options: function () {
            return CompanyBranches.find().map(function (c) {
                return {label: c.companyName+' - '+c.addressCity, value: c._id};
            });
        }
    }
    },
    "active":{
    type: String,
    allowedValues: ["Yes","No"],
    autoform: {
      options: [
        {label: "Yes", value: "Yes"},
        {label: "No", value: "No"}
      ],
      afFieldInput: {
       type: "select-radio-inline"
      }
    }
  },
    services: {
        type: Object,
        optional: true,
        blackbox: true
    },
    roles: {
        type: [String],
        optional: true,
        autoform: {
          options: [
            {label: "Dashboard", value: "Dashboard"},
            {label: "Branches", value: "Branches"},
            {label: "User Profile", value: "User Profile"},
            {label: "Case Managers", value: "Case Managers"},
            {label: "Insurance Company", value: "Insurance Company"},
            {label: "Tasks", value: "Tasks"},
            {label: "Calendar", value: "Calendar"},
            {label: "Contacts", value: "Contacts"},
            {label: "Cases", value: "Cases"},
            {label: "Requests", value: "Requests"},
            {label: "Accounts", value: "Accounts"},
            {label: "Reports", value: "Reports"},
            {label: "Search", value: "Search"},
            {label: "HR", value: "HR"}
          ],
          afFieldInput: {
           type: "select-checkbox-inline"
          }
        }
    }
    });

    Meteor.users.attachSchema(Schemas.User);

This is my Meteor Startup function:

Meteor.startup(function () {
if ( Meteor.users.find().count() === 0 ) {
   Accounts.createUser({ 
        username: "leocrawf@gmail.com",
        email:"leocrawf@gmail.com",
        password: "leoten",
        firstName: "Leocrawf",
        lastName: "Stewart",
        gender:"Male",
        active: "Yes"
      }, function (error) {
        if (error) {
          console.log("Cannot create user");
        }
      });

   }
});

on the server i am doing this in the Accounts.onCreateUser():

Accounts.onCreateUser(function(options, user) {
        user = options || {};
        user.username = options.username;
        user.firstName = options.firstName;
        user.lastName  = options.lastName;   
        user.active    = options.active;
        user.gender    = options.gender;
        // Returns the user object
        return user;
    });

When I query the mongo shell i get this:

meteor:PRIMARY> db.users.find().pretty()
{
"_id" : "pFurR8iDYWJcX9rus",
"username" : "leocrawf@gmail.com",
"firstName" : "Leocrawf",
"lastName" : "Stewart",
"gender" : "Male",
"active" : "Yes",
"services" : {
    "resume" : {
     "loginTokens" : [
            {
    "when" : ISODate("2016-02-05T23:13:38.364Z"),
    "hashedToken" : "vs5xVlKL59yVTO/fbKbSnar38I8ILAruj2W1YecQ2Io="
            }
        ]
     }
   }
 }
Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
jessiPP
  • 436
  • 1
  • 6
  • 21

1 Answers1

1

It doesn't look like you're setting up the profile correctly when creating the user:

Instead of:

Accounts.createUser({ 
  username: "leocrawf@gmail.com",
  email:"leocrawf@gmail.com",
  password: "leoten",
  firstName: "Leocrawf",
  lastName: "Stewart",
  gender:"Male",
  active: "Yes"
},

Try:

Accounts.createUser({ 
  username: "leocrawf@gmail.com",
  email: "leocrawf@gmail.com",
  password: "leoten",
  profile: {
    firstName: "Leocrawf",
    lastName: "Stewart",
    gender: "Male",
    active: "Yes"
  }
},

Also I recommend active: true instead of active: "Yes" to use a boolean instead of a string. It doesn't look like you've defined active or gender in your schema either btw.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
  • Thanks for your response. I have tried that but got this: options.password should be a String. I have never seen any other example where those properties were attached to an options object. – jessiPP Feb 06 '16 at 02:48
  • Profile object, my apologies. Although looking at all this again I'm not sure this is the root cause of your problem. – Michel Floyd Feb 06 '16 at 06:43