Building a Basic Ionic 4 App with User Login and Registration

Building a Basic Ionic 4 App with User Login and Registration

Ionic allows you to develop Progressive Web Applications (PWAs) and hybrid mobile apps. In this tutorial, we'll learn how to build an Ionic 4 App with User Login and Registration.

Ionic allows you to develop Progressive Web Applications (PWAs) and hybrid mobile apps. In this tutorial, we'll learn how to build an Ionic 4 App with User Login and Registration.

**PWAs **are web applications that run in a browser and allow for offline capabilities via service workers. They can be installed on desktops and mobile devices, just like you install apps on your smartphone. Hybrid mobile apps are like native mobile apps, except they're built using web technologies.

Table of Contents

  • Get Started with **Ionic 4 **
  • Create an **Ionic 4 Application **
  • Add **User Login **
  • Add User Registration
  • Run Your **Ionic 4 App on iOS **
  • Run Your **Ionic 4 App on Android **
  • Bonus: You're Using PKCE in the Browser and on Mobile!

**Ionic **2 was based on AngularJS. Ionic 3 was based on Angular. Ionic 4 allows you to use the most popular **JavaScript frameworks **available today: Angular, React, or Vue. This article focuses on the **Angular **version of Ionic 4. I'll show you how to create an Ionic 4 app, add user authentication, and configure things to allow user registration.

If you don't want to code along, feel free to grab the source code from GitHub! You can also watch a video of this tutorial.

Get Started with Ionic 4

To set up your environment to develop with Ionic, complete the following steps:

  1. Install Node.js
  2. Install Ionic CLI using npm
npm install -g [email protected]

Create an Ionic 4 Application

From a terminal window, create a new application using the following command:

ionic start ionic-login tabs

When prompted to install the Ionic Pro SDK, answer no.

It may take a minute or two to create your project, depending on the speed of your internet connection.

Once the process completes, start your Ionic 4 application.

cd ionic-login
ionic serve

This command will open your default browser and navigate to [http://localhost:8100](http://localhost:8100 "http://localhost:8100").

You can use Chrome's device toolbar to see what the application will look like on an iPhone X.

Now let's add a user login feature! Stop the ionic serve process using Ctrl+C before proceeding to the next step.

Add User Login

Schematics is a library from the Angular CLI project that allows you to manipulate projects with code. You can create/update files and add dependencies to any project that has a package.json file. I created an OktaDev Schematics project that makes it possible to add authentication to an Ionic 4 app using one command.

ng add @oktadev/schematics

Before you run this command, you'll need to create an OpenID Connect (OIDC) app in Okta. OIDC builds on top of the OAuth 2.0 authorization framework. It allows clients to verify the identity of the user and get their details. If you're not familiar with OAuth 2.0 or OIDC, I recommend you read What the Heck is OAuth?

Create an OpenID Connect App in Okta

To integrate Okta's Identity Cloud for user authentication, you'll need to signup for a developer account.

Log in to your Okta developer account and navigate to Applications > Add Application.

Select Native and click Next.

Enter a name for your application, such as Ionic 4 App. Add [http://localhost:8100/implicit/callback](http://localhost:8100/implicit/callback "http://localhost:8100/implicit/callback") as a Login redirect URI. Click Done to finish creating the application.

Click Edit and add Logout redirect URIs, where the first should be your reversed Okta domain name, followed by :/logout and the second is [http://localhost:8100/implicit/logout](http://localhost:8100/implicit/logout "http://localhost:8100/implicit/logout"). Click Save.

Near the bottom of your application's settings, you will find a section titled Client Credentials. Copy the Client ID and paste it somewhere handy. You will need this soon.

Navigate to API > Authorization Servers and copy your issuer URI.

Use OktaDev Schematics to Add User Login

Now that you have a client ID and issuer URI, you can install Angular CLI, and add a user login feature using ng add.

npm i -g @angular/[email protected]
ng add @oktadev/schematics --issuer=$issuer --clientId=$clientId

This command performs the following steps:

  1. Adds and installs @oktadev/schematics as a dev dependency
  2. Adds Ionic AppAuth as a dependency
  3. Adds @ionic/storage as a dependency
  4. Adds services, modules, and pages to src/app/auth
  5. Adds a login page and related files to src/app/login
  6. Adds a cordova section to package.json that defines plugins and a custom URL scheme
  7. Updates existing files to handle authentication logic

If you'd like to see the source code for the templates that are installed, you can find them on GitHub.

It's pretty sweet that OktaDev Schematics automates all of this for you, don't you think?!

Test User Login

Start your Ionic 4 application using ionic serve. Your app now has a login button. Click on it to authenticate with Okta using OIDC.

It's likely that you're already logged into your Okta account, so you'll be redirected back to your app and see a screen like the following.

If you click Sign Out and Sign In again, you'll be prompted for your credentials.

After you're redirected back to your app, you can click the User Info button to retrieve your user details from Okta.

Add User Registration

Next, enable user registration. This will allow new users to create their own account. Click on the Users menu and select Registration.

Click Enable Registration.

On the subsequent page, click Save to complete the process of enabling user registration.

Now if you go back to your app, sign out, then sign in again, you'll see a signup link at the bottom of the login form.

Click on the link and you'll see a user registration form. Fill it out and click Register.

You'll receive an email to verify you're real. Click on the Activate Account once you receive it, and you should be good to go!

Run Your Ionic 4 App on iOS

To generate an iOS project for your Ionic application, run the following command:

ionic cordova prepare ios

When prompted to install the ios platform, answer yes. When the process completes, open your project in Xcode:

open platforms/ios/MyApp.xcworkspace

NOTE: If you don't have Xcode installed, you can download it from Apple.

You'll need to configure code signing in the General tab, then you should be able to run in Simulator. Below are screenshots of it running on an emulated iPhone X.

Run Your Ionic 4 App on Android

The most important thing to know when running your Ionic app on Android is that you need Java 8 installed. Anything above Java 8 will not work. If you need to switch between Java SDK versions -- like I often do -- I recommend installing SDKMAN! I ran the command below to downgrade from Java 11 to Java 8 in my terminal window:

sdk use java 8.0.202-amzn

You can then generate an Android project.

ionic cordova prepare android

When prompted to install the android platform, answer yes. After this process completes, open your platforms/android directory as a project in Android Studio.

studio platforms/android

NOTE: You will need to have Android Studio 3.3+ installed and have run Tools > Create Command-line Launcher for the command above to work.

Running with Android Studio 3.3.2

When I first tried this in Android Studio, I received a Gradle Sync error:

The minSdk version should be declared in the android manifest file.

In the right pane, it offered a link for me to click on to fix the issue. I clicked on it, then clicked Do Refactor.

I was prompted to update Gradle and clicked Update.

After these changes, my app showed up in the top toolbar.

Running with Android Studio 3.4

When I tried opening the project in Android Studio 3.4, I was prompted to update Gradle again.

After doing so, I received the following error:

WARNING: The following project options are deprecated and have been removed:
android.useDeprecatedNdk
NdkCompile is no longer supported

I found an open issue in the Cordova Android project that shows how to fix it. Open android/gradle.properties and turn off useDeprecatedNdk.

android.useDeprecatedNdk=false

Set LaunchMode to singleTask

You need to make one additional change for everything to work properly on Android. You need to set the launchMode from singleTop to singleTask so the URL does not trigger a new instance of the app. Edit platforms/android/app/src/main/AndroidManifest.xml to make this change:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
   android:label="@string/activity_name"
   android:launchMode="singleTask"
   android:name="MainActivity"
   android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
   android:windowSoftInputMode="adjustResize">

Now you should be able to click the play button in Android Studio to start your app.

You will be prompted to select an existing AVD (Android Virtual Device) or you can plug in your Android phone and use that. If you have neither, click the Create New Virtual Device Button.

Below are screenshots of the app running on a Pixel 2 AVD.

What About Capacitor?

Capacitor is a project from the Ionic folks that offers an alternative to Cordova. It's currently in beta. The OktaDev Schematics project provides support for Capacitor with a --platform=capacitor flag. For example:

ng add @oktadev/schematics --platform=capacitor

NOTE: This integration uses Ionic's native HTTP plugin for Cordova because the default HTTP from Capacitor uses a capacitor://localhost origin header and Okta only supports http origins.

ECommerce Mobile App Development | Ecommerce Mobile App Development Services

We are leading ecommerce mobile application development company. Hire our ecommerce mobile app developer for your custom Ecommerce project at competitive rates. **Know about [Top ECommerce Mobile App Development...

We are leading ecommerce mobile application development company. Hire our ecommerce mobile app developer for your custom Ecommerce project at competitive rates.

Know about Top ECommerce Mobile App Development Company

Is Low-code or no-code development is future of mobile app development

Is Low-code or no-code development is future of mobile app development

Mobile app development has skyrocketed over these years with the increasing demand of mobile apps for a variety of purposes like entertainment, banking, weather update, health, booking movie tickets, booking a taxi etc. With the latest...

Mobile app development has skyrocketed over these years with the increasing demand of mobile apps for a variety of purposes like entertainment, banking, weather update, health, booking movie tickets, booking a taxi etc. With the latest technologies adopted by mobile app development services, there are different app development approaches which are being practiced. Among them is low-code or no-code development. But will it be the future of mobile app development? Will any mobile application development company start taking this approach as the primary one. Let’s try to find a detailed answer to this question.

But first, let’s understand what this approach exactly is? Well, it is a streamlined approach which involves swift design as well as development with minimal coding, generally relying on different third-party APIs.

Even though there isn’t any single definition of no-code or low-code development because it is actually more of a mindset rather than something which can be directly measured, this mindset has certainly led to a vast community mushrooming up with this mentality. Android app development services are rapidly adopted by this approach. Low-code app innovators are rapidly disrupting all types of various industries. There are a plethora of benefits to these low code platforms and let’s look at this.

1. Less Number of Bugs

It is pretty evident that less code actually means fewer bugs. As simple as that. The entire bug testing phase is actually a major part of modern and latest application development. It is quite inevitable that various issues will come up if there is actually enough code present there. But the best thing regarding low code platforms is that there’s certainly less to test. Also, when they actually tap into APIs, those particular APIs are actually tested by other people.

Lesser number of bugs is better for both users, as well as developers since less amount of time, will be taken up with bug-fixes and troubleshooting. Also, the fast pace of this development approach actually means that if in any case a bug is found, it is generally better just to develop a new iteration rather than fixing it.

2. Significant Lower Costs

Among the most obvious reasons for why you would actually opt for any low code platform is that in reality, low code results in lower cost. Low code development leads to faster app development which saves a lot of time and as a result, lower cost.

It's not only good for companies but also for developers. It certainly cut out the intermediaries, and while they charge less, they use fewer resources and finally come out on top. It is fun for developers because it stops them from actually finding themselves stuck on one particular project which seems to last forever. This is why most of the companies hire app developer who is a well-versed with low-code development.

3. Better Accessibility

The lesser amount of code an application uses, the lesser bandwidth is needed to download it as well as run it. This is quite good news for the people who are based in rural areas or in different developing countries where access to the internet isn’t as prevalent as Western countries. Also, as low code applications can easily be created quite easily than a traditional app, they can easily be released much more swiftly and at a much lower price, and sometimes for free. iPhone app development services follow this approach because it will help in increasing the uptake of their apps as it reduces the entry barrier for every person from lower-income families.

Innovative Development Approach

Among the most promising instances of a low-code or no-code platform is Uber. The apps tap into Google for Maps, Dropbox for storage, Braintree for payments and much more. The most interesting thing about this is that app programming interfaces of APIs which Uber actually relies upon are easily available to anyone who wishes to use them. Uber took those APIs and then used them to create, which was new without requiring to develop each of those particular individual elements, all by themselves. They developed their own brand on top of it by means of looking at how they could actually differentiate themselves from the rest of the others. Mobile app development services should follow this example to create their own low code mobile app which disrupts the market.

The best thing about this is that it inspires innovation. At present, the marketplace actually decides, and only the best applications rise to the top. Also, low code development easily allows developers to iterate much more quickly and can aim for higher more.

The Role of Artificial Intelligence (AI)

Artificial Intelligence is certainly making big waves in different businesses, and as this technology improves further, it will find its way in different other uncharted areas. Among those areas is the low code app development, where it comes in quite useful for a wide range of tasks and actions including the integration of various data sources or just making sense of an entire unstructured or semi-structured data.

Artificial Intelligence is quite great at analysing and conducting trial and error. Hence, it won’t be quite long until the usage of AI becomes quite a standard part of the low code app development. A mobile application development company can find ways to reduce the total amount of code that it is using through AI and flagging potential and possible improvements.

Conclusion

It is quite certain that low-code or no-code app development is the future of app development for one of the simplest reasons that it is quite easier as well as faster and efficiently uses time. It actually doesn’t matter whether Android app development services or iPhone app development services are on-board with this particular change or not. This is quite inevitable as this approach is the path of least resistance. Also, as the inherent demand for low code platforms keeps in growing, developers will certainly find themselves to adopt it.

It is quite a great news as it will push the developers of mobile application development services to become the best. Also, there won’t be any time to redoing it to create the same thing, or any room for sloppy code as well as lengthy development processes which makes the mobile apps redundant even before they are actually finished. Hence, low-code or no-code development will certainly lead the future of mobile app development, and mobile app developers certainly have to get on the bandwagon, one way or the other.

Mobile App Development Company in USA

Mobile App Development Company in USA

**How [Mobile App Development Company in the USA](https://www.dataeximit.com/mobile-app-development-service/ "Mobile App Development Company in the USA"), can breathe life into Your Amazing Ideas?** Today’s Mobile world mobile apps become one of...

How Mobile App Development Company in the USA, can breathe life into Your Amazing Ideas?

Today’s Mobile world mobile apps become one of the important factors in each and every business whether it may be a product based company or a service-based company.

Data EximIT has a strong team of mobile app developers & programmers who have the qualifications and experience in developing apps across several platforms, including iOS, Android, and PhoneGap and. We give our clients complete flexibility with respect to cutting short or extending projects after the minimum term is complete.

Our Mobile App Development Services Are...

  • Android Application Development
  • iOS Application Development
  • Responsive Web Applications
  • Hybrid Mobile Application Development
  • Xamarin Application Development
  • Mobile UI/UX Design

Contact Our Experts For More Information