Getting Cannot read property 'Email' of undefined using meteor and simple-schema

208 Views Asked by At

How can I get Email property using simpl-schema? I'm getting undefined message when using calling Email property. Not sure if anything changed because the implementation is according to the docs.

import { Meteor } from "meteor/meteor";
import SimpleSchema from "simpl-schema";
import { Accounts } from "meteor/accounts-base";

Meteor.startup(() => {
  // code to run on server at startup

  Accounts.validateNewUser(user => {
    const email = user.emails[0].address;

    try {
      new SimpleSchema({
        email: {
          type: String,
          regEx: SimpleSchema.RegEx.Email
        }
      }).validate({ email });
    } catch (e) {
      throw new Meteor.Error(400, e.message);
    }

    return true;
  });
});
0

There are 0 best solutions below