Skip to content

Commit 73aeb30

Browse files
author
nishanth
committed
Updated readme to reflect new features
1 parent 8a525c5 commit 73aeb30

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

auth/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { useAuthState } from 'react-firebase-hooks/auth';
1111
List 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,123 @@ 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](#registerandloginhookusage)
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](#registerandloginhookusage)
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(
148+
auth,
149+
email,
150+
password
151+
);
152+
153+
if (error) {
154+
return (
155+
<div>
156+
<p>Error: {error.message}</p>
157+
</div>
158+
);
159+
}
160+
if (loading) {
161+
return <p>Loading...</p>;
162+
}
163+
if (loggedInUser) {
164+
return (
165+
<div>
166+
<p>Currently LoggedIn User: {loggedInUser.email}</p>
167+
</div>
168+
);
169+
}
170+
if (registeredUser) {
171+
return (
172+
<div>
173+
<p>Currently Registered User: {loggedInUser.email}</p>
174+
</div>
175+
);
176+
}
177+
return (
178+
<div className="App">
179+
<input
180+
type="email"
181+
value={email}
182+
onChange={(e) => setEmail(e.target.value)}
183+
/>
184+
<input
185+
type="password"
186+
value={password}
187+
onChange={(e) => setPassword(e.target.value)}
188+
/>
189+
<button onClick={login}>SIGN IN</button>
190+
<button onClick={register}>SIGN UP</button>
191+
</div>
192+
);
193+
}
194+
195+
export default App;
196+
```

0 commit comments

Comments
 (0)