SimplSchema / Uniforms Name Alias

My users schema (currently) looks like this:

UserSchema = new SimpleSchema(
  {
    username: { type: String, required: true },
    services: Object,
    'services.password': Object,
    'services.password.bcrypt': String,
    'services.resume': { type: Object, blackbox: true },
    emails: { type: Array, label: "Email Addresses" },
    'emails.$': Object,
    'emails.$.address': String,
    'emails.$.verified': Boolean,
    createdAt: Date,
    profile: { type: Object, blackbox: true },
    ...
  },
  { tracker: Tracker, requiredByDefault: false }
);

In order to use Uniforms to create an automatic form field for a password, I need to do this:

<TextField 
     name="services.password.bcrypt"
     label={false} 
     placeholder="Password" 
     showInlineError 
/>

Using the actual name seems to be unsafe? It exposes a direct structure for users’ password hashes? Is there a way to create a name alias to be used in form elements?

More on that, how do I create a single text input for the “emails” field? Is “emails.$.address” correct?

My approach is to use one schema for the input form and another for the MongoDB collection. For example, here’s the schema for an input form:

And here’s the schema for a MongoDB collection:

I find this separation of concerns makes life much easier.

Philip

1 Like