Creating a New Account

In this lesson, we'll create a new account by generating a service to communicate with Firebase.

We'll cover the following

Firebase has an SDK for interacting with it. We can download the SDK by installing the firebase package, which we’ve already done. It will come with methods for signing in and creating users.

The method we’re interested in using is called createUserWithEmailAndPassword(). Information about this function can be found here.

There are two arguments: the email and password. The value returned by this function is a promise in which we’ll handle the response. The only question is: How do we access this method? Thanks to the AngularFire package that we installed, we’ll be able to use dependency injection for the things we need.

Authentication service

We’ll be writing code that will interact with an external API. It’s appropriate to place this code into a service. In the command line, run the following command:

ng generate service auth

This will generate two files: auth.service.ts and auth.service.spec.ts. We’ll be focusing on the auth.service.ts file. Inside it, we’re going to import the AngularFireAuth class from the @angular/fire/auth package.

Get hands-on with 1200+ tech skills courses.