Food Delivery app 2: User Authentication
Email + Password Authentication
Now that the initial setup for our example app is done, we can get to some of the more exciting stuff :) Let’s start by going into the Firebase Console and selecting the Authentication page from the left navigation pane.
Once you’re on the Authentication page, select the Sign-in Methods tab.
This page contains each of the available sign-in methods that you can use in Firebase, so we will be returning to this page multiple times during this article.
For now, select the Email/Password option and click on the Enable toggle. You will also notice a toggle for Email link (passwordless sign-in). Go ahead and enable that toggle as well, as passwordless sign-in is the next authentication type that we will learn about. Click on the blue save button once both of those toggles are enabled.
If you return to the Users tab, you’ll notice that it’s currently empty. Let’s go ahead and change that next.
Email and Password Registration
Return to Android Studio and open main.dart. We’re going to update this file to display a form that lets users enter an email and password to register with Firebase. You can start by adding the following classes:
void _register() async {
final FirebaseUser user = (await
_auth.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
)
).user;
if (user != null) {
setState(() {
_success = true;
_userEmail = user.email;
});
} else {
setState(() {
_success = true;
});
}
}
Comments
Post a Comment