Adding authentication to your app

Most apps need to know the identity of users. For example, in the app we are building in this chapter, we want the user to be able to select their favorite parts of the event program and save that data remotely. In order to do this, we need to know who the user is.

Identifying users generally means two different tasks: 

  • Authentication means confirming the user's identity.
  • Authorization means the user is allowed to access different parts of the app or the data behind the app.

Firebase Authentication provides several services you can leverage in order to provide authentication to your apps, including:

  • Authentication through a username and password, or providers such as Google, Microsoft, Facebook, and several others. Basically, you can delegate the authentication process to an external provider, and your user won't have to remember another username and password to access your data.
  • Creation of user identities.
  • Methods such as Login, Logout, Signup, and Reset password.
  • Integration with other services in Firebase, so you can easily deal with authorization rules once the identity has been created.

In our app, we'll add authentication with a username and password, and we'll allow our users to sign up and sign in. Then, we'll set a rule so that only authenticated users will be able to access the data in our Cloud Firestore database. Also, from our app, we'll give each user the ability to read and write their favorite event details. So, let's see how it's done, as follows: 

  1. In order to enable authentication, we'll need to get back to the Firebase console. From there, we'll get to the Authentication option inside the Develop section of the Firebase project dashboard and click on the Sign-in method tab.
  2. You'll notice that all authentication methods are disabled by default. At this time, we'll only need to enable the Email/Password authentication method. Since we're enabling this provider, we'll be able to sign up and log in with an email and password. In many apps, you may wish to add other providers, such as Google or Facebook, to sign in.
  3. The final result should look similar to the following screenshot:

If you want to learn more about signing in with other providers, have a look at the Further reading section at the end of this chapter.
  1. Make sure you have added the latest version of firebase_auth, the official plugin for authentication maintained by the Firebase team, in the pubspec.yaml file, as follows (for the latest version of the plugin, check https://pub.dev/packages/firebase_auth):
dependencies:
[…]
firebase_auth: ^0.15.5+2

Now that authentication is enabled in our Firebase project, we are ready to create the login screen in our app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.80.34