{"id":467,"date":"2021-11-23T06:32:58","date_gmt":"2021-11-23T12:32:58","guid":{"rendered":"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/?p=467"},"modified":"2022-04-25T09:38:01","modified_gmt":"2022-04-25T14:38:01","slug":"angular-signup-page-with-firebase-authentication","status":"publish","type":"post","link":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/","title":{"rendered":"How to Create a Signup Page with Firebase and Angular"},"content":{"rendered":"\n<p>In this tutorial, you are going to learn how to integrate Firebase Authentication into your Angular project.<\/p>\n\n\n\n<p>If you are unfamiliar with Firebase, Firebase is a platform that allows you to quickly develop websites. If you want to learn more about Firebase, check out their <a href=\"https:\/\/firebase.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"https:\/\/firebase.google.com\/\">website<\/a>.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Create_a_Firebase_Project\" >Create a Firebase Project<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Create_Angular_Project\" >Create Angular Project<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Create_Sign_Up_Page\" >Create Sign Up Page<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Create_the_Form\" >Create the Form<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Time_to_Test\" >Time to Test<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Attempt_to_Sign_Up_with_an_existing_registered_Email\" >Attempt to Sign Up with an existing registered Email<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/angular-signup-page-with-firebase-authentication\/#Wrapping_Up\" >Wrapping Up<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Firebase_Project\"><\/span>Create a <a href=\"https:\/\/console.firebase.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"https:\/\/console.firebase.google.com\/\">Firebase <\/a>Project<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Go to <a href=\"https:\/\/console.firebase.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/console.firebase.google.com\/<\/a>, and create a new project by clicking the \u201cCreate a project\u201d button.<\/p>\n\n\n\n<p>PD: If you are not logged into your Google Account, it will prompt you to log in first.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"549\" height=\"369\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/1-Integrate-Firebase-Authentication-to-Angular-Projects.png\" alt=\"\" class=\"wp-image-1502\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/1-Integrate-Firebase-Authentication-to-Angular-Projects.png 549w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/1-Integrate-Firebase-Authentication-to-Angular-Projects-300x202.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><figcaption>Firebase Console Website<\/figcaption><\/figure><\/div>\n\n\n\n<p>Firebase will prompt you to add the project name and to accept the Firebase terms. Once you do that, click the \u201cContinue\u201d button.<\/p>\n\n\n\n<p>Next, Firebase will ask whether you want to enable Google Analytics for this project. For the purposes of this tutorial, we won\u2019t enable Google Analytics. However, feel free to enable this functionality as Google Analytics allows you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Do A\/B testing<\/li><li>Predict user behavior<\/li><li>Have user segmentation &amp; targeting across Firebase products<\/li><li>Have event-based Cloud functions triggers<\/li><li>Get crash-free users<\/li><li>Get free unlimited reporting<\/li><\/ul>\n\n\n\n<p>If you enabled Google Analytics, you will need to create a Google Analytics project.<\/p>\n\n\n\n<p>Firebase has different pricing plan options. By Default, it will set the Spark plan to your project which is their Free plan. Feel free to navigate to the pricing page to get more details about other plans and their limits.<\/p>\n\n\n\n<p>If you didn\u2019t enable Google Analytics, click on \u201cCreate project\u201d. Once you do this, your project will be created.<\/p>\n\n\n\n<p>Once the project is created, navigate to the Authentication page.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"467\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/2-Integrate-Firebase-Authentication-to-Angular-Projects-1024x467.png\" alt=\"\" class=\"wp-image-1503\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/2-Integrate-Firebase-Authentication-to-Angular-Projects-1024x467.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/2-Integrate-Firebase-Authentication-to-Angular-Projects-300x137.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/2-Integrate-Firebase-Authentication-to-Angular-Projects-768x350.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/2-Integrate-Firebase-Authentication-to-Angular-Projects.png 1140w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Navigate to Firebase Authentication Page<\/figcaption><\/figure><\/div>\n\n\n\n<p>Click the button \u201cGet Started\u201d. You will see all the different sign-in methods available.<\/p>\n\n\n\n<p>For this tutorial, we are going to use Email\/Password sign-in method.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"867\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/3-Integrate-Firebase-Authentication-to-Angular-Projects.png\" alt=\"\" class=\"wp-image-1504\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/3-Integrate-Firebase-Authentication-to-Angular-Projects.png 851w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/3-Integrate-Firebase-Authentication-to-Angular-Projects-294x300.png 294w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/3-Integrate-Firebase-Authentication-to-Angular-Projects-768x782.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><figcaption>Firebase Authentication Sign-in methods<\/figcaption><\/figure><\/div>\n\n\n\n<p>Click the option Email\/Password. Then, Firebase will prompt you to enable this option.<\/p>\n\n\n\n<p>*There is an Email link (passwordless sign-in) option available. This tutorial doesn\u2019t cover the passwordless sign-in method option.<\/p>\n\n\n\n<p>Once you enable Email\/Password, click on \u201cSave\u201d.<\/p>\n\n\n\n<p>Now we are going to get the configuration needed for our project settings. In the left navigation panel, click the \u201cProject Overview\u201d menu option. Select, the Web option to add Firebase to a Web Application project.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"442\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/4-Integrate-Firebase-Authentication-to-Angular-Projects-1024x442.png\" alt=\"\" class=\"wp-image-1505\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/4-Integrate-Firebase-Authentication-to-Angular-Projects-1024x442.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/4-Integrate-Firebase-Authentication-to-Angular-Projects-300x129.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/4-Integrate-Firebase-Authentication-to-Angular-Projects-768x331.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/4-Integrate-Firebase-Authentication-to-Angular-Projects.png 1143w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Create a Web Application Config<\/figcaption><\/figure><\/div>\n\n\n\n<p>Register the app by adding a nickname. Once you registered the app, you will get the Firebase Configuration. Copy them and keep them as we are going to use it once we create our Angular Project.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"877\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/5-Integrate-Firebase-Authentication-to-Angular-Projects-1024x877.png\" alt=\"\" class=\"wp-image-1506\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/5-Integrate-Firebase-Authentication-to-Angular-Projects-1024x877.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/5-Integrate-Firebase-Authentication-to-Angular-Projects-300x257.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/5-Integrate-Firebase-Authentication-to-Angular-Projects-768x657.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/5-Integrate-Firebase-Authentication-to-Angular-Projects.png 1042w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Firebase Project Configuration<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Angular_Project\"><\/span>Create Angular Project<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>First, we need to create our Angular project. Make sure to enable routing whenever the terminal asks if you would like to add Angular routing. If you have already created it, skip this step.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ng new angular-firebase-auth<\/code><\/pre>\n\n\n\n<p>Install default dependencies needed to run the Angular starter project.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>npm i<\/code><\/pre>\n\n\n\n<p>We need to install other packages needed for our application.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>npm i --save bootstrap @angular\/fire firebase<\/code><\/pre>\n\n\n\n<p>To make sure we are using bootstrap CSS library, we are going to open angular.json file and add the bootstrap.css file path to be part of the styles property of the <code>build <\/code>configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code language-js\"><code>\"build\": {\n       \"builder\": \"@angular-devkit\/build-angular:browser\",\n       \"options\": {\n         \"outputPath\": \"dist\/angular-firebase-auth-test-two\",\n         \"index\": \"src\/index.html\",\n         \"main\": \"src\/main.ts\",\n         \"polyfills\": \"src\/polyfills.ts\",\n         \"tsConfig\": \"tsconfig.app.json\",\n         \"aot\": true,\n         \"assets\": &#91;\n           \"src\/favicon.ico\",\n           \"src\/assets\"\n         ],\n         \"styles\": &#91;\n           \"src\/styles.scss\",\n           \".\/node_modules\/bootstrap\/dist\/css\/bootstrap.css\"\n         ],\n         \"scripts\": &#91;]\n       },\n       \"configurations\": {\n         \"production\": {\n           \"fileReplacements\": &#91;\n             {\n               \"replace\": \"src\/environments\/environment.ts\",\n               \"with\": \"src\/environments\/environment.prod.ts\"\n             }\n           ],\n           \"optimization\": true,\n           \"outputHashing\": \"all\",\n           \"sourceMap\": false,\n           \"namedChunks\": false,\n           \"extractLicenses\": true,\n           \"vendorChunk\": false,\n           \"buildOptimizer\": true,\n           \"budgets\": &#91;\n             {\n               \"type\": \"initial\",\n               \"maximumWarning\": \"2mb\",\n               \"maximumError\": \"5mb\"\n             },\n             {\n               \"type\": \"anyComponentStyle\",\n               \"maximumWarning\": \"6kb\",\n               \"maximumError\": \"10kb\"\n             }\n           ]\n         }\n       }\n     },<\/code><\/pre>\n\n\n\n<p>We are going to add Angular Material. Therefore, we are going to run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ng add @angular\/material<\/code><\/pre>\n\n\n\n<p>Once you do so, it will ask you the following questions in the terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>Choose a prebuilt theme name, or \"custom\" for a custom theme:\nSet up global Angular Material typography styles?\nSet up browser animations for Angular Material?<\/code><\/pre>\n\n\n\n<p>Select any prebuilt theme. Also, select Yes to set global Angular Material Typography as well as browser animations for Angular Material.<\/p>\n\n\n\n<p>As you noticed, we installed Bootstrap and Angular Material as we are going to leverage the UI Material Design components and Bootstrap utilities to speed up the development process and have a nice UI interface without spending too much time on adding custom styling to our app. However, installing the @angular\/fire and firebase packages is a requirement to wire up firebase authentication with our signup page.<\/p>\n\n\n\n<p>Open the environment.ts file and add the firebase configuration.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"938\" height=\"574\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/6-Integrate-Firebase-Authentication-to-Angular-Projects.png\" alt=\"\" class=\"wp-image-1507\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/6-Integrate-Firebase-Authentication-to-Angular-Projects.png 938w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/6-Integrate-Firebase-Authentication-to-Angular-Projects-300x184.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/6-Integrate-Firebase-Authentication-to-Angular-Projects-768x470.png 768w\" sizes=\"auto, (max-width: 938px) 100vw, 938px\" \/><figcaption>Add Firebase Configuration in the environment.ts file<\/figcaption><\/figure>\n\n\n\n<p><strong>Note<\/strong>: It is recommended to create at least two separate firebase projects: One for production environments and one for development environment. If you have more environments, it is recommended to create one firebase project per each environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Sign_Up_Page\"><\/span>Create Sign Up Page<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We are going to create a module for the signup page, so in your terminal, run the following command.<\/p>\n\n\n\n<p>Note: Make sure you are in the root folder of your project when executing these commands from your terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ng generate module pages\/signup<\/code><\/pre>\n\n\n\n<p>Then, create the SignupComponent.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ng generate component pages\/signup<\/code><\/pre>\n\n\n\n<p>Now it\u2019s time to update the routes to navigate to the signup page. Open the app-routing.module.ts file and add a new route to the routes variable:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code lang=\"javascript\" class=\"language-javascript\">const routes: Routes = [\n   {\n     path: 'signup',\n     loadChildren: () =&gt;\n       import('.\/..\/app\/pages\/signup\/signup.module').then(\n         (module) =&gt; module.SignupModule\n       ),\n   },\n ];<\/code><\/pre>\n\n\n\n<p>Open the signup.module.ts file and add the RouterModule as part of the Module\u2019s imports. This is with the purpose of setting up the component to be used when navigating to the <code>\/signup<\/code> page. Go ahead and add the FormsModule and ReactiveFormsModule as we will use them to create our signup form. Also, we are going to add some Angular Material modules as we will use them in our template.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code lang=\"javascript\" class=\"language-javascript\">import { NgModule } from '@angular\/core';\n import { CommonModule } from '@angular\/common';\n import { FormsModule, ReactiveFormsModule } from '@angular\/forms';\n import { RouterModule } from '@angular\/router';\n import { MatCardModule } from '@angular\/material\/card';\n import { MatCommonModule } from '@angular\/material\/core';\n import { MatButtonModule } from '@angular\/material\/button';\n import { MatInputModule } from '@angular\/material\/input';\n import { MatToolbarModule } from '@angular\/material\/toolbar';\n import { MatIconModule } from '@angular\/material\/icon';\n import { MatSnackBarModule } from '@angular\/material\/snack-bar';\n import { SignupComponent } from '.\/signup.component';\n @NgModule({\n   declarations: [\n     SignupComponent\n   ],\n   imports: [\n     CommonModule,\n     FormsModule,\n     ReactiveFormsModule,\n     MatCommonModule,\n     MatButtonModule,\n     MatInputModule,\n     MatToolbarModule,\n     MatIconModule,\n     MatSnackBarModule,\n     MatCardModule,\n     RouterModule.forChild([{ path: '', component: SignupComponent }]),\n   ]\n })\n export class SignupModule { }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_the_Form\"><\/span>Create the Form<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this tutorial we are going to use Reactive Driven forms. That\u2019s the reason we included the ReactiveFormsModule in the previous step. Feel free to use Template Driven forms if that approach fits your project best. If you decide to do so, remove the ReactiveFormsModule from the SignupModule to avoid importing unnecessary modules.<\/p>\n\n\n\n<p>Open the signup.component.ts file. Since we are going to generate the form, we need to inject the FormBuilder. Also, we need to set a form property for the SignupComponent class.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code lang=\"javascript\" class=\"language-javascript\">form: FormGroup;\nconstructor(private fb: FormBuilder) { }<\/code><\/pre>\n\n\n\n<p>Generate the form and set the validators for the controls our form will have during the ngOnInit lifecycle hook. We are going to need username, email, and password form controls.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>ngOnInit(): void {\n   this.form = this.fb.group({\n       username: &#91;'', &#91;Validators.required, Validators.minLength(6)]],\n       email: &#91;'', &#91;Validators.required, Validators.email]],\n       password: &#91;'', &#91;Validators.required, Validators.minLength(6)]],\n     });\n }<\/code><\/pre>\n\n\n\n<p>As a recommendation, it is better to create a method that generates the form or sets the form group and call that method during <strong>ngOnInit <\/strong>lifecycle hook. We are helping our code to keep it clean. In my case, I decided to call my method <strong>generateForm<\/strong>. Add accessors for each of the form controls we added to our form (username, email and password).<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>const routes: Routes = &#91;\nimport { Component, OnInit } from '@angular\/core';\n import { FormBuilder, FormControl, FormGroup, Validators } from '@angular\/forms';\n @Component({\n   selector: 'app-signup',\n   templateUrl: '.\/signup.component.html',\n   styleUrls: &#91;'.\/signup.component.scss']\n })\n export class SignupComponent implements OnInit {\n form: FormGroup;\n get usernameControl() {\n     return this.form.get('username') as FormControl;\n   }\n get passwordControl() {\n     return this.form.get('password') as FormControl;\n   }\n get emailControl() {\n     return this.form.get('email') as FormControl;\n   }\n constructor(private fb: FormBuilder) { }\n ngOnInit(): void {\n     this.generateForm();\n   }\n generateForm() {\n     this.form = this.fb.group({\n       username: &#91;'', &#91;Validators.required, Validators.minLength(6)]],\n       email: &#91;'', &#91;Validators.required, Validators.email]],\n       password: &#91;'', &#91;Validators.required, Validators.minLength(6)]],\n     });\n   }\n }<\/code><\/pre>\n\n\n\n<p>Open the SignupComponent template and create the form. Since I have done the heavy lifting for you, you can copy and paste the following html to your signup.component.html file.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;div class=\"d-flex justify-content-center h-100\"&gt;\n  &lt;div class=\"d-flex align-items-center\"&gt;\n    &lt;mat-card&gt;\n      &lt;mat-card-content class=\"p-4\"&gt;\n        &lt;form &#91;formGroup]=\"form\" *ngIf=\"form\" (ngSubmit)=\"onSubmit()\"&gt;\n          &lt;div class=\"row\"&gt;\n            &lt;mat-form-field class=\"w-100\"&gt;\n              &lt;mat-label&gt;Username&lt;\/mat-label&gt;\n              &lt;input matInput type=\"text\" &#91;formControl]=\"usernameControl\" \/&gt;\n              &lt;ng-container *ngIf=\"usernameControl.invalid\"&gt;\n                &lt;mat-error *ngIf=\"usernameControl.required\"&gt;\n                  You must enter your username\n                &lt;\/mat-error&gt;\n                &lt;mat-error *ngIf=\"usernameControl.minlength\"&gt;\n                  Username should have at least 6 alhphanumeric characters\n                &lt;\/mat-error&gt;\n              &lt;\/ng-container&gt;\n            &lt;\/mat-form-field&gt;\n          &lt;\/div&gt;\n \n          &lt;div class=\"row\"&gt;\n            &lt;mat-form-field class=\"w-100\"&gt;\n              &lt;mat-label&gt;Email&lt;\/mat-label&gt;\n              &lt;input matInput type=\"text\" &#91;formControl]=\"emailControl\" \/&gt;\n              &lt;mat-error *ngIf=\"emailControl.invalid\"&gt;\n                You must enter your email\n              &lt;\/mat-error&gt;\n            &lt;\/mat-form-field&gt;\n          &lt;\/div&gt;\n \n          &lt;div class=\"row\"&gt;\n            &lt;mat-form-field class=\"w-100\"&gt;\n              &lt;mat-label&gt;Password&lt;\/mat-label&gt;\n              &lt;input matInput type=\"password\" &#91;formControl]=\"passwordControl\" \/&gt;\n              &lt;ng-container *ngIf=\"usernameControl.invalid\"&gt;\n                &lt;mat-error *ngIf=\"passwordControl.required\"&gt;\n                  You must enter the password\n                &lt;\/mat-error&gt;\n                &lt;mat-error *ngIf=\"passwordControl.minlength\"&gt;\n                  Username should have at least 6 alhphanumeric characters\n                &lt;\/mat-error&gt;\n              &lt;\/ng-container&gt;\n            &lt;\/mat-form-field&gt;\n          &lt;\/div&gt;\n \n          &lt;div class=\"text-center\"&gt;\n            &lt;button\n              mat-raised-button\n              color=\"primary\"\n              type=\"submit\"\n              &#91;disabled]=\"!form.valid\"\n            &gt;\n              Sign Up\n            &lt;\/button&gt;\n          &lt;\/div&gt;\n        &lt;\/form&gt;\n      &lt;\/mat-card-content&gt;\n    &lt;\/mat-card&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>Run your Angular app using the following command if you are relatively new to Angular.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>npm run start<\/code><\/pre>\n\n\n\n<p>Open the browser and navigate to the signup page. If you are using the default port used for Angular projects, the URL will be http:\/\/localhost:4200\/signup. Play around with the interface (there is not too much to play besides filling up a form) and check validations are correctly triggered in the signup form.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"794\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/7-Integrate-Firebase-Authentication-to-Angular-Projects-1024x794.png\" alt=\"\" class=\"wp-image-1508\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/7-Integrate-Firebase-Authentication-to-Angular-Projects-1024x794.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/7-Integrate-Firebase-Authentication-to-Angular-Projects-300x232.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/7-Integrate-Firebase-Authentication-to-Angular-Projects-768x595.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/7-Integrate-Firebase-Authentication-to-Angular-Projects.png 1222w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Signup Page in the localhost <\/figcaption><\/figure><\/div>\n\n\n\n<p>Now we are going to wire up the signup process with firebase. For the next step, we are going to create an <strong>AuthService <\/strong>by running the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ng generate service shared\/auth\/auth<\/code><\/pre>\n\n\n\n<p>Open the auth.service.ts file and inject AngularFireAuth.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>import { Injectable } from '@angular\/core';\nimport { AngularFireAuth } from '@angular\/fire\/auth';\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class AuthService {\n \n  constructor(\n    private firebaseAuth: AngularFireAuth,\n  ) { }\n}<\/code><\/pre>\n\n\n\n<p>Before we set up our request to signup, we need to import AngularFireModule and also set up the firebase configuration using the config values we got from firebase that we stored in the environment.ts file. Open the app.module.ts file and add the following line of code as part of the imports required for the module.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>AngularFireModule.initializeApp(environment.firebaseConfig)<\/code><\/pre>\n\n\n\n<p>The app.module.ts file should look like the following:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>import { BrowserModule } from '@angular\/platform-browser';\nimport { NgModule } from '@angular\/core';\nimport { BrowserAnimationsModule } from '@angular\/platform-browser\/animations';\nimport { environment } from '.\/..\/environments\/environment';\nimport { AngularFireModule } from '@angular\/fire';\n \nimport { AppRoutingModule } from '.\/app-routing.module';\nimport { AppComponent } from '.\/app.component';\n \n@NgModule({\n  declarations: &#91;\n    AppComponent,\n  ],\n  imports: &#91;\n    BrowserModule,\n    AppRoutingModule,\n    BrowserAnimationsModule,\n    AngularFireModule.initializeApp(environment.firebaseConfig),\n  ],\n  providers: &#91;],\n  bootstrap: &#91;AppComponent]\n})\nexport class AppModule { }<\/code><\/pre>\n\n\n\n<p>Then we are going to set up our signUp method. The signUp method is a request to our Firebase Authentication to create a new user for our project.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>signUp(email: string, password: string, username: string) {\n    return this.firebaseAuth.createUserWithEmailAndPassword(email, password)\n  }<\/code><\/pre>\n\n\n\n<p>The last thing we need to do is to wire up the actual signup process. Therefore, we are going to inject the AuthService in our SignupComponent. As a way to notify whether or not the user successfully signed up or not, we are going to use Angular Material Snackbars to display notifications if the process has succeeded or failed. Therefore, we need to inject MatSnackBar to the SignupComponent.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>\/\/ add the following two imports\nimport { MatSnackBar } from '@angular\/material\/snack-bar';\nimport { AuthService } from 'src\/app\/shared\/auth\/auth.service';\n\nexport class SignupComponent implements OnInit {\n  constructor(\n    private fb: FormBuilder,\n    private authService: AuthService,\n    private snackBar: MatSnackBar\n  ) { }<\/code><\/pre>\n\n\n\n<p>Also, we are going to generate a new method in the SignupComponent to make the signup request from the AuthService once the user submits the form. Since we defined in the template that the method <strong>onSubmit <\/strong>is going to be triggered during the form submission, we are going to name our method <strong>onSubmit <\/strong>in our component file.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>\/\/ this is the configuration we have in the signup.component.html file\n(ngSubmit)=\"onSubmit()\"<\/code><\/pre>\n\n\n\n<p>The method should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>onSubmit() {\n    this.authService.signUp(\n      this.emailControl.value,\n      this.passwordControl.value,\n      this.usernameControl.value\n    ).then(\n      () =&gt; {\n        this.snackBar.open('You signed up to this app!');\n      })\n      .catch(\n        (err) =&gt; {\n          this.snackBar.open('There was a problem while trying to sign up a new user');\n        });\n  }<\/code><\/pre>\n\n\n\n<p>Note: Feel free to modify the logic once the request is made. Usually, the new user is redirected to a new page such as the dashboard or main page. To redirect to a new page, you can inject the Router and use the <strong>navigate <\/strong>method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Time_to_Test\"><\/span>Time to Test<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The wait is over. We have done everything described in the tutorial, we followed step-by-step the process of setting up the signup page with Angular and Firebase Authentication. Now, it is time to test. Try signing up a new user on the signup page, and check if the new user has successfully signed up.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"727\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/8-Integrate-Firebase-Authentication-to-Angular-Projects.png\" alt=\"\" class=\"wp-image-1509\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/8-Integrate-Firebase-Authentication-to-Angular-Projects.png 745w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/8-Integrate-Firebase-Authentication-to-Angular-Projects-300x293.png 300w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><figcaption>Testing Sign Up Page<\/figcaption><\/figure><\/div>\n\n\n\n<p>If you noticed, you received a successful notification. That means you successfully signed up for the app. In order to verify I\u2019m not making stuff up, open your firebase project in https:\/\/console.firebase.google.com\/ and navigate to the Authentication page. You will see all the users who have signed up for your application.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects-1024x495.png\" alt=\"\" class=\"wp-image-1510\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects-1024x495.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects-300x145.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects-768x371.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects-1536x743.png 1536w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/9-Integrate-Firebase-Authentication-to-Angular-Projects.png 1716w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Verifying new users in Firebase Authentication Dashboard<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Attempt_to_Sign_Up_with_an_existing_registered_Email\"><\/span>Attempt to Sign Up with an existing registered Email<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Note: if you try to signup with an email you have previously used, you will see an error message. Firebase Authentication won\u2019t allow multiple users with the same email.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"557\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2021\/11\/10-Integrate-Firebase-Authentication-to-Angular-Projects.png\" alt=\"\" class=\"wp-image-1511\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/10-Integrate-Firebase-Authentication-to-Angular-Projects.png 729w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/11\/10-Integrate-Firebase-Authentication-to-Angular-Projects-300x229.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><figcaption>Attempting to Sign Up with the same User<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wrapping_Up\"><\/span>Wrapping Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Congratulations! Now you know how to integrate a signup page using Firebase Authentication for your Angular projects. <\/p>\n\n\n\n<p><strong>How was this tutorial?<\/strong><\/p>\n\n\n\n<p>If you liked this tutorial, share it with other developers who are learning Angular and Firebase. Stay connected with me by following the different social media channels available at becomebetterprogrammer.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">Learning <a href=\"https:\/\/twitter.com\/angular?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">@angular<\/a>?<br><br>Learning <a href=\"https:\/\/twitter.com\/Firebase?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">@Firebase<\/a>?<br><br>Do you need a sign-up page?<br><br>Don&#39;t know how to do it?<br><br>Don&#39;t panic, we got you covered!<br><br>Learn Step By Step How to create a SignUp page with Angular and Firebase Authentication<a href=\"https:\/\/twitter.com\/hashtag\/javascript?src=hash&amp;ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">#javascript<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/tutorial?src=hash&amp;ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">#tutorial<\/a> <a href=\"https:\/\/t.co\/t06fLD7PlE\">https:\/\/t.co\/t06fLD7PlE<\/a><\/p>&mdash; Become A Better Programmer (@bbprogrammer) <a href=\"https:\/\/twitter.com\/bbprogrammer\/status\/1463124789191753730?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">November 23, 2021<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you are going to learn how to integrate Firebase Authentication into your Angular project. <\/p>\n","protected":false},"author":1,"featured_media":1501,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":5,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":2476,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/467\/revisions\/2476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media\/1501"}],"wp:attachment":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}