React
Users

User Registration

9min

Sign up page in React using Parse

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 called Parse.User that automatically handles much of the functionality required for user account management.

In this guide, you will learn how the Parse.User class works by creating a user registration feature for your React App using Parse JS SDK.

Prerequisites

To complete this tutorial, you will need:

Goal

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

1 - Understanding the SignUp method

Parse User management uses the Parse.User object type, which extends the default ParseObject type while containing unique helper methods, such as current and getUsername, that will help you retrieve user data throughout your app. You can read more about the Parse.User object here at the official documentation.

In this guide, you will learn how to use the signUp method that creates a new valid and unique Parse.User object both locally and on the server, taking as arguments valid username and password values.

2 - Create the user registration component

Let’s now build the functional component, which will call the signUp method in our App. First, create a new file in your src directory called UserRegistration.js (UserRegistration.tsx if you are using TypeScript) and also add the needed input elements (username and password inputs), using state hooks via useState to manage their data:

UserRegistration.js
UserRegistration.tsx


3 - Create a Sign Up function

You can now create the sign-up function that will call the signUp method:

JavaScript
TypeScript


Note: Creating a new user using signUp also makes it the currently logged-in user, so there is no need for your user to log in again to continue using your App.

Insert this function inside the UserRegistration component, just before the return call, to be called and tested. Remember to update the form’s sign up button onClick action to () => doUserRegistration(). Your component should now look like this:

UserRegistration.js
UserRegistration.tsx


Also add these classes to your App.css file to fully render the layout styles:

App.css


Your app now should look like this:

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


Conclusion

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

Updated 29 Mar 2024
Did this page help you?