rdiazroman
rdiazroman

Reputation: 429

AngularFireAuth. Create user with additional field

Is it possible to create users in Firebase with an additional field? In my code, I can create them with "email", and "password".

  this.af.auth.createUser({
    name: formData.value.name,  // gives error*
    email: formData.value.email,
    password: formData.value.password
  }).then(

*error:

signup.component.ts (26,9): Argument of type '{ name: any; email: any; password: any; }' is not assignable to parameter of type 'EmailPasswordCredentials'. Object literal may only specify known properties, and 'name' does not exist in type 'EmailPasswordCredentials'.

I'd like to add additional fields, like "date of birth", "displayName", etc.

Many thanks

Upvotes: 3

Views: 1448

Answers (1)

Steven Scott
Steven Scott

Reputation: 11270

According to the documentation you cannot do this. However, you can add these additional fields into the data. I use a User Settings structure, where the same User Id is, and then you have a full structure available.

I use a folder of the base data structure, UserSettings, to hold the custom fields, and then get this data at the same time as I handle the authentication, in an Angular data provider.

"UserSettings": {
    // User Specified Settings should be read/write by the user
    "$user_id": {
        ".read": "$user_id === auth.uid",
        ".write": "$user_id === auth.uid"
    }
}

Firebase Data

+ - /UserSettings
    + /<user id string>
        + Name
        + BirthDate

Upvotes: 2

Related Questions