<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ionic 5 Firebase Email Auth]]></title><description><![CDATA[<p dir="auto">In this article i'm going to show you how to integrate firebase email login for ionic apps and pwa's. I'll cover all the basic stuff like login, register, forgot password, logout and profile.</p>
<p dir="auto">First i will introduce about firebase and ionic 5.</p>
<p dir="auto"><strong>What is Firebase</strong></p>
<p dir="auto">I'm sure you have heard about firebase before, if not don't worry i'll tell you about firebase. Firebase is a Backend-as-a-Service (BaaS) that started in 2011 and backed by google. The main advantage of using firebase is we don't want to have a server, firebase is the our server, it has rich feature set that can make fully functional dynamic mobile apps without our own API, Database etc… See below for main features of firebase -</p>
<ul>
<li>Analytics</li>
<li>Realtime Database</li>
<li>Push Notification</li>
<li>Authentication</li>
<li>Firestore</li>
<li>and many more...</li>
</ul>
<p dir="auto">In this article we use firebase authentication feature. Firebase provides many sign-in methods.</p>
<p dir="auto"><img src="/assets/uploads/files/1585755828924-image-20200329220353563-resized.png" alt="image-20200329220353563.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">We use <strong>Email/Password</strong> sign-in method in this article. In next part i will talk about social logins like Google, Facebook.</p>
<p dir="auto"><strong>What is ionic?</strong></p>
<p dir="auto">Ionic is a open source SDK for develop high performance hybrid mobile apps and progressive web apps(PWA). It uses HTML5, CSS, JS technologies to develop apps &amp; pwa's, sounds good, no? With that web technologies you can made powerfull and look and feel beautifull apps for any platform or device.</p>
<p dir="auto">Why you should choose hybrid technologies over native apps? because if you develop a native app, for Android you have to use <strong>Java</strong> and for iOS you have to use <strong>Objective C</strong> or <strong>Swift</strong>, you have to develop seperately for each platform. That is very expensive and take lot of time. In that hybrid technologies you can use same codebase for different platforms like Android, iOS, Windows also you can list them on native app stores.</p>
<p dir="auto"><strong>Steps</strong></p>
<ol>
<li>Create Firebase Project</li>
<li>Create Ionic 5 app</li>
<li>Connect Ionic app to Firebase</li>
<li>Implementing Email/Password sign-in</li>
<li>Implementing Forgot Password</li>
</ol>
<p dir="auto">Ok, let's start it.</p>
<p dir="auto"><strong>Step 1 - Firebase Project</strong></p>
<p dir="auto">If you have used firebase before you can skip this step, for beginners follow below steps,</p>
<ul>
<li>Go to <a href="https://console.firebase.google.com/" target="_blank" rel="noopener noreferrer nofollow ugc">Firebase Console</a></li>
<li>Sign in with your google account</li>
<li>Firebase dashboard should look like this</li>
</ul>
<p dir="auto"><img src="/assets/uploads/files/1585755884680-image-20200329221859778-resized.png" alt="image-20200329221859778.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">Then click on **Add Project</p>
<p dir="auto"><img src="/assets/uploads/files/1585755908617-image-20200329222039975-resized.png" alt="image-20200329222039975.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">Enter name for the project and click <strong>Continue</strong> button, for this project i'm use <strong>authapp</strong> for project name</p>
<p dir="auto"><img src="/assets/uploads/files/1585755932968-image-20200329222306396-resized.png" alt="image-20200329222306396.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">In next step, disable <strong>Enable Google Analytics for this project</strong> and click on <strong>Create Project</strong> button, now go inside the project, it look like this,</p>
<p dir="auto"><img src="/assets/uploads/files/1585755957304-image-20200329222706304-resized.png" alt="image-20200329222706304.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">Now click on <strong>Authentication</strong> located on left side bar</p>
<p dir="auto"><img src="/assets/uploads/files/1585755973188-image-20200329223406237-resized.png" alt="image-20200329223406237.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">And click on <strong>Sign-in method</strong> tab on the top, then enable the <strong>Email/Password</strong> option</p>
<p dir="auto">This step is done.</p>
<p dir="auto"><strong>Step 2 - Create Ionic 5 app</strong></p>
<p dir="auto">To create ionic app, you have to install <strong>ionic-cli</strong>, <strong>nodejs</strong>, <strong>npm</strong> on your machine. If you havent setup those softwares, please follow <a href="https://ionicframework.com/docs/installation/cli" target="_blank" rel="noopener noreferrer nofollow ugc">this link</a> before proceeding.</p>
<p dir="auto">Let's create the project, open your terminal and <strong>cd</strong> to empty directory and enter the following command</p>
<p dir="auto"><code>ionic start auth-app blank</code></p>
<p dir="auto">This will generate an blank starter ionic app on our directory, after project creation, run <code>ionic serve</code> to run in on browser.</p>
<p dir="auto"><strong>Step 3 - Connect Ionic app to Firebase</strong></p>
<p dir="auto">First we need to generate firebase configuration for our app, to do this go to firebase console and follow the steps,</p>
<p dir="auto"><img src="/assets/uploads/files/1585756039330-image-20200331212557750-resized.png" alt="image-20200331212557750.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">Click on <strong>&lt;/&gt;</strong> icon on the dashboard,</p>
<p dir="auto"><img src="/assets/uploads/files/1585756057799-image-20200331212703640-resized.png" alt="image-20200331212703640.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">Give a nickname and click on <strong>Register app</strong> button</p>
<p dir="auto">After copy the below configuration part from the firebase,</p>
<pre><code>// Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "AIzaSyDkq5rm-**************************",
    authDomain: "*****************************",
    databaseURL: "***********************************",
    projectId: "************",
    storageBucket: "************************",
    messagingSenderId: "***********",
    appId: "************************************"
  };
</code></pre>
<p dir="auto">Now open <code>src/environments/environment.ts</code> &amp; <code>src/environments/environment.prod.ts</code>  file and past the configuration just copied,</p>
<p dir="auto"><img src="/assets/uploads/files/1585756155662-image-20200331213532176-resized.png" alt="image-20200331213532176.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">To communicate with firebase and use firebase methods we use <strong>AngularFire2</strong> package. Install package from <strong>npm</strong></p>
<p dir="auto"><code>npm i firebase @angular/fire</code></p>
<p dir="auto">Now we have to import Angular Fire Module to our app module, open <code>src/app/app.module.ts</code> ,</p>
<pre><code>import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

// Angular Fire Module
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';

import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,
    //Initializing Firebase App
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFireAuthModule
  ],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
</code></pre>
<p dir="auto">Now our app able to communicate with firebase app, so we can now proceed to implement Email/Password sign-in.</p>
<p dir="auto"><strong>Step 4 - Implementing Email/Password sign-in</strong></p>
<p dir="auto">For this we need two pages, one for <strong>Login</strong> other for <strong>Register</strong>, lets create both pages using ionic cli, run below commands on root of the project,</p>
<p dir="auto"><code>ionic g page Login</code></p>
<p dir="auto"><code>ionic g page Register</code></p>
<p dir="auto">Now open <strong>login.page.html</strong> page and put below code.</p>
<pre><code>&lt;ion-header&gt;
  &lt;ion-toolbar&gt;
    &lt;ion-buttons slot="start"&gt;
      &lt;ion-back-button&gt;&lt;/ion-back-button&gt;
    &lt;/ion-buttons&gt;
    &lt;ion-title&gt;Login&lt;/ion-title&gt;
  &lt;/ion-toolbar&gt;
&lt;/ion-header&gt;

&lt;ion-content class="ion-padding"&gt;
  &lt;ion-item&gt;
    &lt;ion-label position="floating"&gt;Email&lt;/ion-label&gt;
    &lt;ion-input [(ngModel)]="email"&gt;&lt;/ion-input&gt;
  &lt;/ion-item&gt;
  &lt;ion-item&gt;
    &lt;ion-label position="floating"&gt;Password&lt;/ion-label&gt;
    &lt;ion-input [(ngModel)]="password"&gt;&lt;/ion-input&gt;
  &lt;/ion-item&gt;

  &lt;ion-button expand="block" class="ion-margin-vertical" (click)="login()"&gt;LOGIN&lt;/ion-button&gt;

  &lt;div class="ion-text-center"&gt;
    Don't have an account? &lt;span routerLink="/register" routerDirection="forward"&gt;Sign-up&lt;/span&gt;
  &lt;/div&gt;
&lt;/ion-content&gt;
</code></pre>
<p dir="auto">It will looks like this,</p>
<p dir="auto">Now open <strong>register.page.html</strong> and put below code,</p>
<pre><code>&lt;ion-header&gt;
  &lt;ion-toolbar&gt;
    &lt;ion-buttons slot="start"&gt;
      &lt;ion-back-button&gt;&lt;/ion-back-button&gt;
    &lt;/ion-buttons&gt;
    &lt;ion-title&gt;Register&lt;/ion-title&gt;
  &lt;/ion-toolbar&gt;
&lt;/ion-header&gt;

&lt;ion-content class="ion-padding"&gt;
  &lt;ion-item&gt;
    &lt;ion-label position="floating"&gt;Email&lt;/ion-label&gt;
    &lt;ion-input [(ngModel)]="email"&gt;&lt;/ion-input&gt;
  &lt;/ion-item&gt;
  &lt;ion-item&gt;
    &lt;ion-label position="floating"&gt;Password&lt;/ion-label&gt;
    &lt;ion-input [(ngModel)]="password"&gt;&lt;/ion-input&gt;
  &lt;/ion-item&gt;

  &lt;ion-button expand="block" class="ion-margin-vertical" (click)="register()"&gt;REGISTER&lt;/ion-button&gt;

  &lt;div class="ion-text-center"&gt;
    Already have an account? &lt;span routerLink="/login" routerDirection="backward"&gt;Sign-in&lt;/span&gt;
  &lt;/div&gt;
&lt;/ion-content&gt;
</code></pre>
<p dir="auto">Now open <strong>login.page.ts</strong> and put below code</p>
<pre><code>import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Router } from '@angular/router';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {

  email: any;
  password: any;

  constructor(
    private fireauth: AngularFireAuth,
    private router: Router,
    private alertCtrl: AlertController
  ) { }

  ngOnInit() {
  }

  login() {
    this.fireauth.auth.signInWithEmailAndPassword(this.email, this.password)
      .then((res) =&gt; {
        if (res.user) {
          // Login Success
          this.router.navigate(['home']);
        }
      }).catch((err) =&gt; {
        let msg = err.message;

        this.presentAlert("Error", msg);
      })
  }

  async presentAlert(header, msg) {
    const alert = await this.alertCtrl.create({
      header: header,
      message: msg,
      buttons: ['OK']
    });

    await alert.present();
  }

}
</code></pre>
<p dir="auto">Now open <strong>register.page.ts</strong></p>
<pre><code>import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Router } from '@angular/router';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-register',
  templateUrl: './register.page.html',
  styleUrls: ['./register.page.scss'],
})
export class RegisterPage implements OnInit {

  email: any;
  password: any;

  constructor(
    private fireauth: AngularFireAuth,
    private router: Router,
    private alertCtrl: AlertController
  ) { }

  ngOnInit() {
  }

  register() {
    this.fireauth.auth.createUserWithEmailAndPassword(this.email, this.password)
      .then((res) =&gt; {
        if (res.user) {
          // Register Success
          this.router.navigate(['home']);
        }
      }).catch((err) =&gt; {
        let msg = err.message;

        this.presentAlert("Error", msg);
      })
  }

  async presentAlert(header, msg) {
    const alert = await this.alertCtrl.create({
      header: header,
      message: msg,
      buttons: ['OK']
    });

    await alert.present();
  }

}
</code></pre>
<p dir="auto">Now open <strong>home.page.html</strong></p>
<pre><code>&lt;ion-header [translucent]="true"&gt;
  &lt;ion-toolbar&gt;
    &lt;ion-title&gt;
      Home
    &lt;/ion-title&gt;
  &lt;/ion-toolbar&gt;
&lt;/ion-header&gt;

&lt;ion-content class="ion-padding"&gt;
  &lt;strong&gt;Welcome&lt;/strong&gt;
    
  &lt;ion-button expand="block" class="ion-margin-vertical" (click)="logout()"&gt;LOG OUT&lt;/ion-button&gt;
&lt;/ion-content&gt;
</code></pre>
<p dir="auto">Now open <strong>home.page.ts</strong></p>
<pre><code>import { Component } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Router } from '@angular/router';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor(
    private fireauth: AngularFireAuth,
    private router: Router,
    private alertCtrl: AlertController
  ) {}

  logout() {
    this.fireauth.auth.signOut()
      .then(() =&gt; {
        this.router.navigate(['login']);
      })
      .catch((err) =&gt; {
        let msg = err.message;

        this.presentAlert("Failed", msg);
      });
  }

  async presentAlert(header, msg) {
    const alert = await this.alertCtrl.create({
      header: header,
      message: msg,
      buttons: ['OK']
    });

    await alert.present();
  }
}
</code></pre>
<p dir="auto">Now open <strong>app-routing.module.ts</strong>, made changes like below</p>
<pre><code>import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'home', loadChildren: () =&gt; import('./home/home.module').then( m =&gt; m.HomePageModule)},
  {
    path: 'login',
    loadChildren: () =&gt; import('./login/login.module').then( m =&gt; m.LoginPageModule)
  },
  {
    path: 'register',
    loadChildren: () =&gt; import('./register/register.module').then( m =&gt; m.RegisterPageModule)
  },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }
</code></pre>
<p dir="auto">Ok now we're done with firebase email sign-in &amp; sign-out, now you can run the app by <code>ionic serve</code> and check our work, in future article i'll cover other more features of firebase auth, stay tuned.</p>
]]></description><link>https://lankadevelopers.lk/topic/545/ionic-5-firebase-email-auth</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 19:26:13 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/545.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Apr 2020 15:52:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Sat, 02 May 2020 17:55:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/326">@kusalrathna</a> ekatath tutorial ekak hadannm</p>
]]></description><link>https://lankadevelopers.lk/post/3357</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3357</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Sat, 02 May 2020 17:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Fri, 01 May 2020 19:15:15 GMT]]></title><description><![CDATA[<p dir="auto">ionic firebase DB එකත් ඔ​නේ</p>
]]></description><link>https://lankadevelopers.lk/post/3354</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3354</guid><dc:creator><![CDATA[kusalrathna]]></dc:creator><pubDate>Fri, 01 May 2020 19:15:15 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Sat, 04 Apr 2020 22:27:58 GMT]]></title><description><![CDATA[<p dir="auto">awesome, keep it up</p>
]]></description><link>https://lankadevelopers.lk/post/3242</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3242</guid><dc:creator><![CDATA[ciaompe]]></dc:creator><pubDate>Sat, 04 Apr 2020 22:27:58 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Sat, 04 Apr 2020 07:38:03 GMT]]></title><description><![CDATA[<p dir="auto">@isuru2014 thanks bro</p>
]]></description><link>https://lankadevelopers.lk/post/3232</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3232</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Sat, 04 Apr 2020 07:38:03 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Fri, 03 Apr 2020 16:52:50 GMT]]></title><description><![CDATA[<p dir="auto">Great 💪</p>
]]></description><link>https://lankadevelopers.lk/post/3231</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3231</guid><dc:creator><![CDATA[imadusanka]]></dc:creator><pubDate>Fri, 03 Apr 2020 16:52:50 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Thu, 02 Apr 2020 07:50:30 GMT]]></title><description><![CDATA[<p dir="auto">@cody  <a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a>  thanks bro</p>
]]></description><link>https://lankadevelopers.lk/post/3230</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3230</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 02 Apr 2020 07:50:30 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Thu, 02 Apr 2020 07:46:16 GMT]]></title><description><![CDATA[<p dir="auto">Superb bro</p>
]]></description><link>https://lankadevelopers.lk/post/3229</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3229</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Thu, 02 Apr 2020 07:46:16 GMT</pubDate></item><item><title><![CDATA[Reply to Ionic 5 Firebase Email Auth on Thu, 02 Apr 2020 03:57:40 GMT]]></title><description><![CDATA[<p dir="auto">thanks bro</p>
]]></description><link>https://lankadevelopers.lk/post/3228</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3228</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Thu, 02 Apr 2020 03:57:40 GMT</pubDate></item></channel></rss>