Skip to content

Commit 743d558

Browse files
author
Scott Prue
committed
fix(docs): cleanup unnessesary code in auth examples and add note about how authIsReady is only for SSR environments
1 parent 20c6e38 commit 743d558

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

docs/recipes/auth.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ import { connect } from 'react-redux'
1212
import { withFirebase, isLoaded, isEmpty } from 'react-redux-firebase'
1313
// import GoogleButton from 'react-google-button' // optional
1414

15-
export function LoginPage ({ firebase, auth }) {
15+
function LoginPage ({ firebase, auth }) {
16+
function loginWithGoogle() {
17+
return firebase.login({ provider: 'google', type: 'popup' })
18+
}
1619
return (
1720
<div className={classes.container}>
18-
{/* <GoogleButton/> button can be used instead */ }
19-
<button onClick={() => firebase.login({ provider: 'google', type: 'popup' })}>
20-
Login With Google
21-
</button>
2221
<div>
2322
<h2>Auth</h2>
2423
{
2524
!isLoaded(auth)
2625
? <span>Loading...</span>
2726
: isEmpty(auth)
28-
? <span>Not Authed</span>
27+
// <GoogleButton/> button can be used instead
28+
? <button onClick={loginWithGoogle}>Login With Google</button>
2929
: <pre>{JSON.stringify(auth, null, 2)}</pre>
3030
}
3131
</div>
@@ -55,28 +55,18 @@ import PropTypes from 'prop-types'
5555
import { compose } from 'redux'
5656
import { connect } from 'react-redux'
5757
import { withFirebase, isLoaded, isEmpty } from 'react-redux-firebase'
58-
// import GoogleButton from 'react-google-button' // optional
5958

60-
function LoginPage ({ firebase, auth }) {
61-
// Wait for auth to load
59+
function AuthPage ({ firebase, auth }) {
6260
if (!isLoaded(auth)) {
63-
61+
return <span>Loading...</span>
62+
}
63+
if (isEmpty(auth)) {
64+
return <span>Not Authed, Please Login</span>
6465
}
6566
return (
66-
<div className={classes.container}>
67-
<button // <GoogleButton/> button can be used instead
68-
onClick={() => firebase.login({ provider: 'google', type: 'popup' })}
69-
>Login With Google</button>
70-
<div>
71-
<h2>Auth</h2>
72-
{
73-
!isLoaded(auth)
74-
? <span>Loading...</span>
75-
: isEmpty(auth)
76-
? <span>Not Authed</span>
77-
: <pre>{JSON.stringify(auth, null, 2)}</pre>
78-
}
79-
</div>
67+
<div>
68+
<h3>Auth Data</h3>
69+
<pre>{JSON.stringify(auth, null, 2)}</pre>
8070
</div>
8171
)
8272
}
@@ -133,12 +123,14 @@ reactReduxFirebase(fbConfig, rrfConfig)
133123

134124
Now when logging in through `login` method, user will be listed as online until they logout or end the session (close the tab or window).
135125

136-
**Note:** Currently this is not triggered on logout, but that is a [planned feature for the upcoming v3.0.0 version](https://github.com/prescottprue/react-redux-firebase/wiki/v3.0.0-Roadmap). Currently, the presense status will only change when the user becomes disconnected from the Database (i.e. closes the tab).
126+
**NOTE:** Currently this is not triggered on logout, but that is a [planned feature for the upcoming v3.0.0 version](https://github.com/prescottprue/react-redux-firebase/wiki/v3.0.0-Roadmap). Currently, the presense status will only change when the user becomes disconnected from the Database (i.e. closes the tab).
137127

138128
## Wait For Auth To Be Ready (SSR)
139129

140130
Waiting for auth to be ready is usually only required in an SSR environment.
141131

132+
**NOTE:** This should only be used to prevent loading in a server side environment - if this is done directly on a client it can cause long application bootup times.
133+
142134
```js
143135
import firebase from 'firebase'
144136
import { compose, createStore, applyMiddleware } from 'redux'
@@ -188,6 +180,8 @@ In order for this to work, the promise must know the name of the location within
188180

189181
If you want to write your own custom logic for the promise that actually confirms that auth is ready, you can pass a promise as the `authIsReady` config option.
190182

183+
**NOTE:** This should only be used to prevent loading in a server side environment - if this is done directly on a client it can cause long application bootup times.
184+
191185
Here is an example showing the default logic:
192186

193187
```js

0 commit comments

Comments
 (0)