@@ -11,6 +11,8 @@ import { useAuthState } from 'react-firebase-hooks/auth';
1111List of Auth hooks:
1212
1313- [ useAuthState] ( #useauthstate )
14+ - [ useRegister] ( #useregister )
15+ - [ useLogin] ( #uselogin )
1416
1517### useAuthState
1618
@@ -30,6 +32,8 @@ Returns:
3032- ` loading ` : A ` boolean ` to indicate whether the the authentication state is still being loaded
3133- ` error ` : Any ` firebase.auth.Error ` returned by Firebase when trying to load the user, or ` undefined ` if there is no error
3234
35+ #### If you are registering or logingIn the user for the first time consider using [ useRegister] ( #useregister ) , [ useLogin] ( #uselogin )
36+
3337#### Full Example
3438
3539``` js
@@ -70,3 +74,121 @@ const CurrentUser = () => {
7074 return < button onClick= {login}> Log in < / button> ;
7175};
7276```
77+
78+ ### useRegister
79+
80+ ``` js
81+ const [registeredUser , error , register , loading ] = useRegister ( auth, email, password );
82+ ```
83+
84+ Import statement :
85+
86+ ``` js
87+ import { useRegister } from ' react-firebase-hooks/auth' ;
88+ ```
89+
90+ For full full example [ check here] ( #register-and-login-hook-usage )
91+
92+ Register a user and receive the user credentials
93+
94+ The ` useRegister ` hook takes the following parameters:
95+
96+ - ` auth ` : ` firebase.auth.Auth ` instance for the app you would like to monitor
97+ - ` email ` : ` string ` email of the user
98+ - ` password ` : ` string ` password of the user
99+
100+ Returns:
101+
102+ - ` registeredUser ` : The ` registeredUser ` if data is received or ` undefined ` if not
103+ - ` loading ` : A ` boolean ` to indicate whether the the registration is completed or it's yet processing
104+ - ` error ` : ` any ` returned by Firebase when trying to register the user, or ` undefined ` if there is no error
105+ - ` register ` : ` void ` a function you can call to start the registration
106+
107+ ### useLogin
108+
109+ ``` js
110+ const [loggedInUser , error , login , loading ] = useLogin (auth, email, password);
111+ ```
112+
113+ Import statement :
114+
115+ ``` js
116+ import { useLogin } from ' react-firebase-hooks/auth' ;
117+ ```
118+
119+ For full full example [ check here] ( #register-and-login-hook-usage )
120+
121+ Register a user and receive the user credentials
122+
123+ The ` useLogin ` hook takes the following parameters:
124+
125+ - ` auth ` : ` firebase.auth.Auth ` instance for the app you would like to monitor
126+ - ` email ` : ` string ` email of the user
127+ - ` password ` : ` string ` password of the user
128+
129+ Returns:
130+
131+ - ` loggedInUser ` : The ` loggedInUser ` if data is received or ` undefined ` if not
132+ - ` loading ` : A ` boolean ` to indicate whether the the login process is completed or it's yet processing
133+ - ` error ` : ` any ` returned by Firebase when trying to register the user, or ` undefined ` if there is no error
134+ - ` login ` : ` void ` a function you can call to start the login process
135+
136+ ## Register and Login hook usage
137+
138+ ``` jsx
139+ import React , { useState } from ' react' ;
140+ import { auth } from ' ./firebase' ;
141+ import { useLogin , useRegister } from ' react-firebase-hooks/auth' ;
142+
143+ function App () {
144+ const [email , setEmail ] = useState (' ' );
145+ const [password , setPassword ] = useState (' ' );
146+ const [loggedInUser , error , login , loading ] = useLogin (auth, email, password);
147+ const [registeredUser , error , register , loading ] = useRegister (auth, email, password);
148+
149+ // Use only one of the above two hooks in one file
150+
151+ if (error) {
152+ return (
153+ < div>
154+ < p> Error : {error .message }< / p>
155+ < / div>
156+ );
157+ }
158+ if (loading) {
159+ return < p> Loading... < / p> ;
160+ }
161+ if (loggedInUser) {
162+ return (
163+ < div>
164+ < p> Currently LoggedIn User: {loggedInUser .email }< / p>
165+ < / div>
166+ );
167+ }
168+ if (registeredUser) {
169+ return (
170+ < div>
171+ < p> Currently Registered User: {loggedInUser .email }< / p>
172+ < / div>
173+ );
174+ }
175+ return (
176+ < div className= " App" >
177+ < input
178+ type= " email"
179+ value= {email}
180+ onChange= {(e ) => setEmail (e .target .value )}
181+ / >
182+ < input
183+ type= " password"
184+ value= {password}
185+ onChange= {(e ) => setPassword (e .target .value )}
186+ / >
187+ < button onClick= {login}> SIGN IN < / button>
188+ < button onClick= {register}> SIGN UP < / button>
189+ < / div>
190+ );
191+ }
192+
193+ export default App ;
194+ ```
0 commit comments