Flutter
...
User Authentication
Authentication

User Registration

15min

User Registration for Flutter using Parse Server

Introduction

At the core of many apps, user accounts have a notion that lets users securely access their information. Parse provides a specialized User class that automatically handles much of the functionality required for user account management. With this class, you’ll be able to add user account functionality to your app.

ParseUser is a subclass of the ParseObject, and has the same features. All the methods that are on ParseObject also exist in ParseUser. The difference is that ParseUser has some special additions specific to user accounts. ParseUser has several properties that set it apart from ParseObject:

  • username: The username for the user (required).
  • password: The password for the user (required on signup).
  • email: The email address for the user (optional).

You are free to use an email address as the username. Ask your users to enter their email, but fill it in the username property — ParseUser will work as normal.

In this guide, you will learn how to use the Flutter plugin for Parse Server to manage users using ParseUser class creating a user registration feature for your Flutter App.



Goal

To build a User Registration feature using Parse for a Flutter App.

Prerequisites

To complete this tutorial, you will need:

Understanding the SignUp App

To better understand the SignUp process, we will create an app to register user data and create your account. We won’t explain the Flutter application code once this guide’s primary focus is using the Flutter with Parse. Following the next steps, you will build a Todo App that will store the tasks at Back4App Database.

Let’s get started!

Following the next steps you will be able to build a Sign App that will create user Account in Back4App Database.

1 - Create Sign App Template

Open your Flutter project from the previous guide Flutter plugin for Parse Server. Go to the main.dart file, clean up all the code, and replace it with:

Dart


When debug parameter in function Parse().initialize is true, allows displaying Parse API calls on the console. This configuration can assist in debugging the code. It is advisable to disable debug in the release version.

2 - Connect Template to Back4app Project

Find your Application Id and Client Key credentials navigating to your app Dashboard at Back4App Website.

Update your code in main.dart with the values of your project’s ApplicationId and ClientKey in Back4app.

  • keyApplicationId = App Id
  • keyClientKey = Client Key

Run the project, and the app will load as shown in the image.

Document image


3 - Code for Sign User

The User SignUp function creates a new user in your Parse App. Before that, it checks to make sure that both the username and email are unique. If a SignUp isn’t successful, you should check the error object that is returned. The most likely cause is that another user has already taken the username or email. You should communicate this to your users and ask them to try a different username.

Search for the function doUserRegistration in the file main.dart. Replace the code inside doUserRegistration with:

Dart


To build this function, follow these steps:

  1. Make a new instance of the ParseUser class with the command ParseUser.createUser(username, password, email), with data that were filled in the app.
  2. Call the signUpfunction, which will register user to your database in the Parse Dashboard.
  3. Check if user signup with success. If not success, show error description message.

The complete code should look like this:

Dart


To test it, click on the Run button in Android Studio/VSCode.

Document image


After providing the desired user credentials, you will see this message after pressing on Sign Up if everything was successful:

Document image


Error handling can be tested if you try to register a user with the same username as before:

Document image


You will get another error if you try to sign up with no password:

Document image


4 - Check User Registration on Dashboard

  1. Login at Back4App Website
  2. Find your app and click on Dashboard>Core>Browser>User.

At this point, you should see your user as displayed below:

Document image


It’s done!

At the end of this guide, you learned how to register new Parse users on Flutter. In the next guide, we will show you how to log in and out users.

Updated 04 Jun 2024
Did this page help you?