Twitter LogoFacebook Logo
Firebase Authentication: Creating Users
Creating users in Firebase using the FirebaseTS package
By: King

Before you get started, you must add the FirebaseTS library to your project. Follow this tutorial to learn how to add FirebaseTS.

https://codeible.web.app/view/tutorial/wRV99AyHd46WzxTDRq58

Also, make sure to enable the email and password sign in method for the Firebase project.

In this tutorial, we will be using the createAccountWith() method from the FirebaseTSAuth class.

Here is the definition of the method:

public createAccountWith(params: {
        email: string, 
        password: string, 
        onComplete?: (userCredentials: firebase.auth.UserCredential) => void,
        onFail?: (error: any) => void
}): Promise<firebase.auth.UserCredential>;

Setup

1. Import the FirebaseTSAuth class.

import FirebaseTSAuth from 'firebasets/firebasetsAuth/firebaseTSAuth';

2. Instantiate an FirebaseTSAuth object.

private authFirebaseTSAuth;
  constructor(){ 
    this.auth new FirebaseTSAuth();
}

3. Call the createAccountWith() method and populate the email and password fields.

this.auth.createAccountWith(

   {
       email: "codeible@codeible.com",
       password: "*******"
   }
);

Handling code on complete or fail

Sometimes, you may want to execute some code afterwards. Add the onComplete and onFail callback functions.

this.auth.createAccountWith(
   {
       email: "codeible@codeible.com",
       password: "*******",
       onComplete: (uc) => {
          alert("Signed in!");
        },
       onFail: (err) => {
          alert("Failed to Sign in...");
       }
   }
);

We can also use the then() and catch() methods since the createAccountWith() method is a promise.

this.auth.createAccountWith(

   {
       email: "",
       password: ""
   }
)
.then( uc => { ... } )
.catch( err => { ... } );


Sign In