Passwordless Email Link Login Using Firebase Auth in Ionic Angular App
Tags: emaillogin, passwordlesslogin, firebase, ionicangular
Published: 2022-06-30 07:49:34

---
title: Passwordless Email Link Login Using Firebase Auth in Ionic Angular App
published: true
date: 2022-03-07 07:21:10 UTC
tags: emaillogin,passwordlesslogin,firebase,ionicangular
canonical_url: https://enappd.com/blog/passwordless-email-link-login-using-firebase/185/ 
---

![](https://cdn-images-1.medium.com/max/1024/1*PRTcA0iAuNdk48bWmoutCw.png)

In this tutorial, we will learn how to perform an **Email Link Signup** with both **password** and **passwordless** methods. Most of the tutorial only contains the passwordless method but in the end, we will cover Email Link Signup with Password as well. We will use the Ionic 5 application which is based on the Angular framework — with Firebase (the most popular combo). However this tutorial can be followed for another framework also like React and Vue, only changes will be in a few steps.

If you want to know more about any of these topics or any other tech stack you can explore [HERE](https://enappd.com/blog/).

### What is Ionic 5?

You probably already know about Ionic, but I’m putting it here just for the sake of beginners, feel free to skip this section. **Ionic** is a complete open-source SDK for hybrid mobile app development created by [Max Lynch](https://medium.com/u/a76fa51de1ba), [Ben Sperry](https://medium.com/u/14b1be5c1354), and Adam Bradley of Drifty Co. in 2013. Ionic provides tools and services for developing hybrid mobile apps using Web technologies like CSS, HTML5, and Sass. Apps can be built with these Web technologies and then distributed through native app stores to be installed on devices by leveraging Cordova.

So, in other words — If you create Native apps in Android, you code in Java. If you create Native apps in iOS, you code in Obj-C or Swift. Both of these are powerful but complex languages. **With Cordova (and Ionic) you can write a single piece of code for your app that can run on both iOS and Android.** (and windows!), that too with the simplicity of HTML, CSS, and JS. Now the Ionic team has released **Capacitor** as a replacement for Cordova — however, that will not impact much of this tutorial.

### Steps for Email-based Signup :

I will go ahead in a step-by-step fashion so you can follow easily.

1. **Create a Firebase project** and explore the **Firebase Auth**
2. Create a basic **Ionic 5 Angular app**
3. Connect your **Ionic 5 Angular app with Firebase** and code the Email Link Logic
4. Email Link Signup Application **Build**.

### 1. Create a Firebase project and explore Firebase Auth

Go to [Firebase](https://console.firebase.google.com/) and create your first project (or use an existing one). Your console should look like this :

![](https://cdn-images-1.medium.com/max/800/1*Q1tzpM83Uq66TNZ9E28nYA.png)


**Note**  — It’s really easy to create a Firebase project, but if you still face any issue, follow steps 1–4 of [this blog](https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23/)

Click on your project and you’ll enter the project’s dashboard. Look for the **Authentication** tab. This is where the magic will happen!

![Authentication Tab in Firebase Console](https://cdn-images-1.medium.com/max/1024/1*SBQuZCsLovmTwg8PLYh5YQ.png)


In the Authentication tab, we have various options to explore like Users, Sign In Methods, and more.

1. **Users Tab** :- Initially this tab may look empty as you have not signed up any users. But once users start coming to your app, this tab shows the details of Signed Up users like their **username** or **email Id** , **Provider** (Type of login : Email Login, Social Logins or another type of login), and **User ID** (unique id which identifies the user). We can disable or delete any user in our Firebase Project.
2. **Sign In Methods** :- This tab, helps us to enable the sign-in methods, which we will use to implement Email Link Login in the Ionic 5 Angular App. To enable the Email Link Login, first, we have to enable the Email Login.

![Sign-in methods](https://cdn-images-1.medium.com/max/1005/1*tlXWdBdLezM7IJgHQ2xjig.jpeg)


We have different options for sign-in, like Email Login, social logins (Google, Facebook and Twitter), phone login, apple login, Microsoft login, and more. Now we will look at Email Login with Email Link Authentication. Enable the Email/password Auth and Email Link (passwordless authentication). [If you want to explore other Auth methods we have [various blogs](https://enappd.com/blogcategory/5/)on those ]

![Email Link Authentication](https://cdn-images-1.medium.com/max/868/1*n38vXnDpxpV5JhFENJQAvQ.jpeg)


After Enabling, our firebase work is completed now we have to proceed to sstep 2.

### 2. Create a basic Ionic 5 app

Creating a basic Ionic 5 Angular app is very easy. Assuming you have all basic requirements installed in your system, run

```
$ ionic start MyApp blank
```

This creates your app with a titleMyApp and a blank template.

> For more details on how to create a basic Ionic 5 app, refer to my blog [How to create an Ionic 5 app](https://enappd.com/blog/how-to-create-an-ionic-app-for-beginners/144/)

### 3. Integrate firebase with Ionic 5 App and Add Email Link Logic

In this Part, we will cover two methods for Email Link Signup:-

i) Email Link Signup using passwordless Sign in:-

ii) Email Link Signup using with Password:-

The above two methods can be used to Signup in the Ionic 5 App, but this restricts the user to enter the valid username. The procedure for Email Link Signup is as follows:-

- The user will enter the Email Id.
- An email verification link will be sent to the entered Email Id.
- When we click on the Email link provided in the mail, then the control will be redirected to the Ionic application. (will use Firebase Dynamic Link Plugin).
- At Last, the Ionic 5 App will check for the deep links provided in the clicked Link and redirect the user to the Home Page.

Now we know the flow, so we can go with the flow and start to code:-

![](https://cdn-images-1.medium.com/max/500/1*PREww8ceV27kzp5j4ocm2g.gif)

#### 3.1 Create a Firebase project

To create a firebase project, goto [Firebase Console](https://console.firebase.google.com/u/0/) and create a new project (if you do not have it already).

![Your Firebase projects all in one place](https://cdn-images-1.medium.com/max/800/1*Q1tzpM83Uq66TNZ9E28nYA.png)


**Note**  — It’s really easy to create a Firebase project, but if you still face any issue, follow step 1–4 of [this blog](https://enappd.com/blog/connect-firebase-with-ionic-5-app/134)

Click on your project and you’ll enter the project’s dashboard (as shown below). Look for the **Authentication** tab. This is where the magic will happen !

![](https://cdn-images-1.medium.com/max/1024/1*IZs6_QEsITbIPlJkmRdDKg.png)

Here you have to enable **Email/Password authentication** type. This will help us to login using email link and password.

Once you are ready with the Firebase Project, now we have to **_create an android app_** into the firebase project.

#### 3.2 Create Android app in Firebase

For setting up options, you’ll first have to create an Android app in Firebase console. During the process, it will ask you to enter app’s **package name** and provide **google-services.json.**

To create android app you can goto **Project settings** and add the app from there.

![Project settings](https://cdn-images-1.medium.com/max/1024/1*7a9OOyo8fdP-KvqiZdN4XQ.png)

And then click on the **Add App** button to add a new Android/iOS or web application. In our example we will create and Android App.

> Make sure you keep the package name same as what you are setting in config.xml file of Ionic app.

![Download google-services.json](https://cdn-images-1.medium.com/max/1024/1*rtd51fTn_frvjGxUEkhiow.png)


#### 3.3 Installing Required Packages for Ionic App

Before starting we will install the required packages in our Ionic 5 Angular application like firebase, [firebase dynamic link Plugin](https://ionicframework.com/docs/native/firebase-dynamic-links). To install firebase we need to install [@angular/fire](http://twitter.com/angular/fire) which provides the various firebase modules like Auth Module, Firestore Module, Storage Module, and more.

To install angular fire run the below command in your project root directory:-

```
$ npm install @angular/fire
```

#### 3.4 Configure Dynamic links in Firebase Console

To make Dynamic links work, first, you have to enable the Dynamic Links in the Firebase console.

![Firebase Dynamic Link](https://cdn-images-1.medium.com/max/1024/1*gFER4W_YtGBrIIQFI_nv1A.png)


Now we have to set up the Dynamic link, by setting the domain name. The domain is already suggested by the Firebase, you should select it by default it will configure itself and finally, you can use it in your app.

![Setting Domain in Dynamic Link](https://cdn-images-1.medium.com/max/873/1*NahSjFUBWQihQCaIXuSzMg.jpeg)


#### 3.5 Configuring the Ionic 5 Angular App

Then we will use this domain while installing the Firebase Dynamic Links Plugin like used below command (run the command in Ionic App’s root project directory):-

```
$ cordova plugin add cordova-plugin-firebase-dynamiclinks --variable APP_DOMAIN_NAME="mydomain.page.link"

$ npm install @ionic-native/firebase-dynamic-links
```

**You must use “your” dynamic link value in APP\_DOMAIN\_NAME and replace the mydomain.page.link**. Once the plugin is installed, we have to configure it by adding some lines in Config.xml.

```
<platform name="ios">
    <preference name="GoogleIOSClientId" value="..." />
</platform>
<platform name="android">
    <preference name="GoogleAndroidClientId" value="..." />
</platform>
```

You can get your GoogleAndroidClientId from **google-services.json** file, which you can download from Firebase **Project settings**.

![](https://cdn-images-1.medium.com/max/569/1*P_t6ZuBgXBxmJULo7iud7w.png)

![Project Settings](https://cdn-images-1.medium.com/max/1010/1*EYFH2CqADCwOVTC52MIvLw.png)

In **google-services.json** , you will get the key in _object_._client[0].oauth\_client[0].client\_id_, below is the piece of code using which you can identify.

![](https://cdn-images-1.medium.com/max/892/1*SQiKV3LR4zGBtgHoo980Jg.png)

#### 3.6 Injecting the Required Packages in App.module.ts

Now we have installed the packages and added the config in **config.xml** , Now we import them in **app.module.ts** , Below code is of app module file.

{% gist https://gist.github.com/vaibhavgehani/f53bb961c77b03f112526e720bc2ab33 %}

#### 3.7 Adding UI code to the Ionic 5 application

Now we have to add UI to the Ionic 5 application, We will have a signup page with Auth services, API services.

1. Signup page:-

![Signup Page](https://cdn-images-1.medium.com/max/279/1*nhGSSlCxszkrX8W8ZCmx1A.jpeg)

The signup page will look like above, **signup.page.html** will be coded as:-

{% gist https://gist.github.com/vaibhavgehani/fa8de0d0067fef590b95ad82d0acbb7b %}

Now HTML work is done, we will now add the logic in the signup page for Email Link signup with password:-

{% gist https://gist.github.com/vaibhavgehani/aebb77866628947f7cbb4c12d8af55d6 %}

**_EmailLinkSignup()_**, will be called after filling in the details and clicking on signup. below is the code for **_EmailLinkSignup();_**

{% gist https://gist.github.com/vaibhavgehani/d54b6cdeccc5cef0a57c998063091e30 %}

**sendsignInUsingEmailLink()** function will be called, It will send the Email to the entered Email Id with verification/redirecting link. The following operation will be performed by the below code:-

```
async sendsignInUsingEmailLink(_email_: _string_) {
  _console_.log(email);
  _const_ actionCodeSettings = {
    url: ` **\*\*hosted\_app\_URL\*\*** `,
    handleCodeInApp: true,
    android: {
       packageName: ' ****your\_app\_id****'
    }
  };
   return await this.fireAuth.auth.sendSignInLinkToEmail(email, actionCodeSettings);
} 
```

To get the **hosted\_app\_URL**  , you can go and follow these steps in this [Blog](https://enappd.com/blog/firebase-with-ionic-4-hosting-auth-and-db-connection/58/). And to get the **your\_app\_id** you can go to config.xml under the widget tag like below:-

```
<widget id="com.example.xxxx" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
```

After this function is executed, you will get a mail from firebase. To sign in using the Link like below:-

![](https://cdn-images-1.medium.com/max/320/1*YnEOBM9puuonWOePt8N5KA.jpeg)

We have now completed the first step to send the mail to the input Email Id, and now we have to code for redirection from the link to the App. To do that we will use the Firebase Dynamic Links Plugin.

#### 3.8 Adding Subscriber to the App Component file

Now we will add a subscriber, that will let us know that we have come through the Dynamic Link in the Mail. You can set this subscriber where ever you want, but the best practice is to put it under app.component.ts like stated below:-

{% gist https://gist.github.com/vaibhavgehani/d9b9aee49f00690ca6f99b14b5b023c0 %}

The above function **_setEmailLinkSubscriber()_** can be called under the constructor, so this function will listen for the Link clicks from the user. And you can perform any function you want. The local data stored is users data, the reason to store this locally is as many users exits the app and then enter the app using Dynamic link (Provided in Mail).

The most important function is **signInUsingEmailLink()**, defined under **authService**. This will differ if you want a passwordless signup vs a password sign-up.

#### Passwordless Signup :-

This is quite easy, we only have to call the **_this.fireAuth.auth.signInWithEmailLink()_** with **_email: string_** , **_emailLink: string_** as the parameters ( email Id was already stored in local storage and dynamic link response (res.deepLink) provides deep link).

```
return this.fireAuth.auth.signInWithEmailLink(email, deeplink);
```

#### With Password Signup :-

This method can also be called as 2 -way authentication system, as it first authenticates using the Email Link and secondly it verifies the user with input Password. So to do that follow the below line of code in auth Service.

{% gist https://gist.github.com/vaibhavgehani/9143b40c0568e6bccaed707dfd0950ee %}

Now once we have verified that user has come through the Email Link, now we can simply create user using the **_this.fireAuth.auth.createUserWithEmailAndPassword(email, password)_**, which will create user using the email and password.

### 4. Build the Android Application

To add and build the Android application, run the below commands :-

```
$ ionic cordova platform add android
$ ionic cordova run android
```

Below video is for a completed application, same flow can be seen in your application also.

![](https://cdn-images-1.medium.com/max/296/1*w5hGtqGt1CPsg0pSvoP_PQ.gif)

### Conclusion

Now we have enough knowledge to implement the Email Link (with password or passwordless), so we can add one more functionality to our awesome Ionic 5 application and if you want to add more of the functionality in your app. You can visit out [Blog Section](https://enappd.com/blog/).

### Next Steps

If you liked this blog, you will also find the following Ionic blogs interesting and helpful. Feel free to ask any questions in the comment section

- Ionic Payment Gateways — [Stripe](https://enappd.com/blog/ionic-4-stripe-payment-integration-with-firebase-for-apps-and-pwa/17) | [PayPal](https://enappd.com/blog/ionic-4-paypal-payment-integration-for-apps-and-pwa/16) | [Apple Pay](https://enappd.com/blog/how-to-integrate-apple-pay-in-ionic-4-apps/21) | [RazorPay](https://enappd.com/blog/how-to-integrate-razorpay-in-ionic-4-apps-and-pwa/20)
- Ionic Charts with — [Google Charts](https://enappd.com/blog/ionic-4-charts-using-google-charts/66)| [HighCharts](https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-3/60) | [d3.js](https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-2/54) | [Chart.js](https://enappd.com/blog/charts-in-ionic-4-apps-and-pwa-part-1/52)
- Ionic Social Logins — [Facebook](https://enappd.com/blog/facebook-login-in-ionic-4-apps-using-firebase/25) | [Google](https://enappd.com/blog/google-login-in-ionic-4-apps-using-firebase/39) | [Twitter](https://enappd.com/blog/twitter-login-in-ionic-4-apps-using-firebase/24)
- Ionic Authentications — [Via Email](https://enappd.com/blog/email-authentication-with-firebase-in-ionic-4/38) | [Anonymous](https://enappd.com/blog/firebase-anonymous-login-in-ionic-4/37)
- Ionic Features — [Geolocation](https://enappd.com/blog/using-geolocation-geocoding-and-reverse-geocoding-in-ionic-4/45) | [QR Code reader](https://enappd.com/blog/qr-code-scanning-and-optical-character-recognition-ocr-in-ionic-4/9)| [Pedometer](https://enappd.com/blog/best-fitness-plugins-for-ionic-4-how-to-use-pedometer/15)
- Media in Ionic — [Audio](https://enappd.com/blog/spotify-like-music-in-ionic-4-apps/48) | [Video](https://enappd.com/blog/adding-video-player-in-ionic-4-app/64) | [Image Picker](https://enappd.com/blog/image-picker-in-ionic-4-app/67) | [Image Cropper](https://enappd.com/blog/how-to-add-image-cropper-in-ionic-4-app/68)
- Ionic Essentials — [Native Storage](https://enappd.com/blog/ionic-4-save-and-retrieve-data-locally-on-device/59) | [Translations](https://enappd.com/blog/how-to-translate-in-ionic-4-globalization-internationalization-and-localization/11) | [RTL](https://enappd.com/blog/rtl-right-to-left-use-in-ionic-4/50)
- Ionic messaging — [Firebase Push](https://enappd.com/blog/implement-ionic-4-firebase-push/34) | [Reading SMS](https://enappd.com/blog/automatically-read-sms-in-ionic-4-apps/42)
- Ionic with Firebase — [Basics](https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23) | [Hosting and DB](https://enappd.com/blog/firebase-with-ionic-4-hosting-auth-and-db-connection/58) | [Cloud functions](https://enappd.com/blog/firebase-cloud-functions-in-ionic-4-complete-guide/32)

### Ionic React Full App with Capacitor

If you need a base to start your next Ionic 5 React Capacitor app, you can make your next awesome app using [Ionic 5 React Full App in Capacitor](https://store.enappd.com/product/ionic-react-full-app-capacitor/)

![Ionic 5 React Full App in Capacitor from Enappd](https://cdn-images-1.medium.com/max/760/1*G3yOFVX4oABx9MhUy-3kng.png)

### Ionic Capacitor Full App (Angular)

If you need a base to start your next Angular **Capacitor app** , you can make your next awesome app using [Capacitor Full App](https://store.enappd.com/product/capacitor-full-app-with-ionic-angular/)

![Capacitor Full App with huge number of layouts and features](https://cdn-images-1.medium.com/max/736/0*UwSHcofTMStMnzAX.png)

### Ionic Full App (Angular and Cordova)

If you need a base to start your next Ionic 5 app, you can make your next awesome app using [Ionic 5 Full App](https://store.enappd.com/product/ionic-full-app)

![Ionic Full App with huge number of layouts and features](https://cdn-images-1.medium.com/max/700/0*1ArpKyhiDHZnevwB.jpeg)


* * *