WEBVTT

1
00:00:00.320 --> 00:00:02.180
Hi and welcome to this video.

2
00:00:02.200 --> 00:00:03.900
Today we're going to be talking about how

3
00:00:03.930 --> 00:00:09.460
to create a user using firebase and I want
to show you how easy and simple it is.

4
00:00:09.480 --> 00:00:11.500
We're now looking at the Firebase project

5
00:00:11.530 --> 00:00:13.980
that I created for the
donation application.

6
00:00:14.010 --> 00:00:18.540
And if I refresh we're going to see
that we have no user so far.

7
00:00:18.560 --> 00:00:24.500
So what I want to show you is how
we're going to create this user.

8
00:00:24.530 --> 00:00:26.940
First of all we're going to need an API

9
00:00:26.970 --> 00:00:31.220
folder where we're going to be
placing all our API calls.

10
00:00:31.240 --> 00:00:33.540
And inside it we're going to create user

11
00:00:33.570 --> 00:00:43.620
JS file and here we're going to import
auth from react native firebase/auth

12
00:00:43.650 --> 00:00:48.340
and we're going to create a new exportable
function create

13
00:00:48.370 --> 00:00:53.340
user and we're going to take in the user's
full name, email and password.

14
00:00:53.370 --> 00:00:56.020
And we're going to use
this to create the user.

15
00:00:56.040 --> 00:00:57.780
What we're going to do is use the try

16
00:00:57.810 --> 00:01:04.340
catch and we're going to try to create
a user using auth,

17
00:01:04.370 --> 00:01:07.850
create user with email and password
and we're going to give it email

18
00:01:07.880 --> 00:01:11.770
and password because that's
the information that it needs.

19
00:01:11.800 --> 00:01:13.020
And we're going to have to make sure

20
00:01:13.050 --> 00:01:18.930
that this is an Asynchronous call and that
we can await to complete this action.

21
00:01:18.960 --> 00:01:23.020
And once we complete this action,
if we are successful and we have no

22
00:01:23.050 --> 00:01:28.740
errors, then what we want to do
is update the user's full name.

23
00:01:28.770 --> 00:01:33.180
So for that we're going to use await user

24
00:01:33.210 --> 00:01:38.340
update
profile and we're going to give it

25
00:01:38.370 --> 00:01:43.850
an object saying that display name should
be full name

26
00:01:43.880 --> 00:01:50.700
and the we're just going to return
user and console log the user's

27
00:01:50.730 --> 00:01:54.210
information and then let's
create the catch block.

28
00:01:54.240 --> 00:01:57.840
And here we're going to get an error
just in case if we have it.

29
00:01:57.870 --> 00:01:59.900
And we're going to say if

30
00:01:59.930 --> 00:02:09.100
error code equals auth/email-already-in-use,

31
00:02:09.130 --> 00:02:17.860
we want to console log
that email address is already in use.

32
00:02:17.890 --> 00:02:23.480
Let's say else if error.code

33
00:02:24.760 --> 00:02:29.540
auth/invalid-email
the we're going to console log

34
00:02:29.570 --> 00:02:38.260
that email address is invalid, otherwise
let's just console log the error.

35
00:02:38.290 --> 00:02:46.140
And now we're going to use this function
whoops I need user user update profile

36
00:02:46.170 --> 00:02:51.260
here and then we're going to use this
function on our registration page.

37
00:02:51.290 --> 00:02:57.660
And here I'm going to create onpress event
and that is going to be Asynchronous.

38
00:02:57.690 --> 00:03:03.140
We're going to await for the create user
function and make sure that this is

39
00:03:03.170 --> 00:03:07.820
imported and let's pass in our
full name, email and password.

40
00:03:07.850 --> 00:03:13.460
So full name, email and password
from whatever user enters here.

41
00:03:13.490 --> 00:03:15.480
And here we're just going to say

42
00:03:15.510 --> 00:03:21.900
that we're creating a user for Nata Vacheishvili
and that my email address is

43
00:03:21.930 --> 00:03:28.240
nata@vacheishvili.com and I'm just going
to enter some password and then I'm going

44
00:03:28.270 --> 00:03:31.100
to click on registration
and it should work.

45
00:03:31.130 --> 00:03:33.740
So let's see what happens.

46
00:03:33.770 --> 00:03:38.780
Click and we get the user's information.

47
00:03:38.810 --> 00:03:41.340
Get that display name is null just because

48
00:03:41.370 --> 00:03:45.700
we didn't console log what happened
after we updated the name.

49
00:03:45.730 --> 00:03:47.220
But here we go here's

50
00:03:47.250 --> 00:03:52.340
the email Nata Vacheishvili, email verified is
false because I haven't verified it.

51
00:03:52.370 --> 00:03:54.700
There's no phone number, no photo URL.

52
00:03:54.730 --> 00:03:57.700
And here's our refresh token.

53
00:03:57.730 --> 00:04:00.820
And if we want to use it,
we can use it for logging in.

54
00:04:00.850 --> 00:04:02.820
And now if I go to Firebase,

55
00:04:02.850 --> 00:04:08.420
we're going to see that there is something
created for that user right now.

56
00:04:08.450 --> 00:04:11.420
So what happens if I retry to do this?

57
00:04:11.450 --> 00:04:14.740
So let's try that here.

58
00:04:14.770 --> 00:04:17.100
I get an error saying that email address

59
00:04:17.130 --> 00:04:24.420
is already in use, and this is what
the Firebase returns as an error.

60
00:04:24.450 --> 00:04:27.140
And if I give it an invalid email address,

61
00:04:27.160 --> 00:04:33.860
let's say this is my email address,
that email address is invalid.

62
00:04:33.890 --> 00:04:39.220
So Firebase does all of this work for us,
and we're going to use this information

63
00:04:39.250 --> 00:04:44.700
to make sure that we handle the success
and error messages in the next video.

64
00:04:44.720 --> 00:04:46.700
I'm very excited for our next step.

65
00:04:46.720 --> 00:04:47.960
So see you in the next video.

