Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 743
rdiazroman Avatar asked Feb 27 '26 17:02

rdiazroman


1 Answers

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
like image 171
Steven Scott Avatar answered Mar 02 '26 06:03

Steven Scott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!