Hi and welcome to this video.
Today we're going to be talking about how
to create a user using firebase and I want to show you how easy and simple it is.
We're now looking at the Firebase project
that I created for the donation application.
And if I refresh we're going to see that we have no user so far.
So what I want to show you is how we're going to create this user.
First of all we're going to need an API
folder where we're going to be placing all our API calls.
And inside it we're going to create user
JS file and here we're going to import auth from react native firebase/auth
and we're going to create a new exportable function create
user and we're going to take in the user's full name, email and password.
And we're going to use this to create the user.
What we're going to do is use the try
catch and we're going to try to create a user using auth,
create user with email and password and we're going to give it email
and password because that's the information that it needs.
And we're going to have to make sure
that this is an Asynchronous call and that we can await to complete this action.
And once we complete this action, if we are successful and we have no
errors, then what we want to do is update the user's full name.
So for that we're going to use await user
update profile and we're going to give it
an object saying that display name should be full name
and the we're just going to return user and console log the user's
information and then let's create the catch block.
And here we're going to get an error just in case if we have it.
And we're going to say if
error code equals auth/email-already-in-use,
we want to console log that email address is already in use.
Let's say else if error.code
auth/invalid-email the we're going to console log
that email address is invalid, otherwise let's just console log the error.
And now we're going to use this function whoops I need user user update profile
here and then we're going to use this function on our registration page.
And here I'm going to create onpress event and that is going to be Asynchronous.
We're going to await for the create user function and make sure that this is
imported and let's pass in our full name, email and password.
So full name, email and password from whatever user enters here.
And here we're just going to say
that we're creating a user for Nata Vacheishvili and that my email address is
nata@vacheishvili.com and I'm just going to enter some password and then I'm going
to click on registration and it should work.
So let's see what happens.
Click and we get the user's information.
Get that display name is null just because
we didn't console log what happened after we updated the name.
But here we go here's
the email Nata Vacheishvili, email verified is false because I haven't verified it.
There's no phone number, no photo URL.
And here's our refresh token.
And if we want to use it, we can use it for logging in.
And now if I go to Firebase,
we're going to see that there is something created for that user right now.
So what happens if I retry to do this?
So let's try that here.
I get an error saying that email address
is already in use, and this is what the Firebase returns as an error.
And if I give it an invalid email address,
let's say this is my email address, that email address is invalid.
So Firebase does all of this work for us, and we're going to use this information
to make sure that we handle the success and error messages in the next video.
I'm very excited for our next step.
So see you in the next video.