Authenticate a User in React with Firebase

faraz ahmad
Instructorfaraz ahmad

Share this video with your friends

Send Tweet
Published a year ago
Updated a year ago

🔥 Firebase provides several easy-to-use authentication methods that we can use to handle auth in React apps.

In this lesson, we will cover how to authenticate a user via an email and password. This is done using createUserWithEmailAndPassword function available to us from the firebase library.

You'll need firebase configured in your application which you can read about here.

Faraz Ahmad: [0:00] After we've configured Firebase with our configuration options, we were able to use the Firebase library in our application. In this file, if the user is not authenticated, we display a SignupForm. If they are authenticated, we will display a message along with the user object that is returned from Firebase.

[0:18] First, import firebase from "firebase/app" and also import the auth module. We're going to use the createUserWithEmailAndPassword function and pass in our email and password from state. We'll make this an async function and await the user that is returned from firebase.auth(). createUserWithEmailAndPassword.

[0:41] Once we get the user, we'll pass it to our onSuccess callback. After the user fills out the form, they will be authenticated and can see our app along with the user object.