Skip to content

Commit 5d44df6

Browse files
author
Scott Prue
committed
fix(docs): remove v2 auth ready docs from v3 docs - #676
1 parent ac5d18b commit 5d44df6

File tree

5 files changed

+38
-98
lines changed

5 files changed

+38
-98
lines changed

docs/recipes/auth.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -114,81 +114,6 @@ export default compose(
114114
)(LoginPage)
115115
```
116116

117-
118-
## Wait For Auth To Be Ready
119-
120-
```js
121-
import firebase from 'firebase'
122-
import { compose, createStore, applyMiddleware } from 'redux'
123-
import { reactReduxFirebase } from 'react-redux-firebase'
124-
125-
// Firebase config
126-
const fbConfig = {
127-
apiKey: '<your-api-key>',
128-
authDomain: '<your-auth-domain>',
129-
databaseURL: '<your-database-url>',
130-
storageBucket: '<your-storage-bucket>'
131-
}
132-
// react-redux-firebase options
133-
const rrfConfig = {
134-
userProfile: 'users', // firebase root where user profiles are stored
135-
attachAuthIsReady: true, // attaches auth is ready promise to store
136-
firebaseStateName: 'firebase' // should match the reducer name ('firebase' is default)
137-
}
138-
139-
const createStore = (initialState = {}) => {
140-
// Initialize Firebase instance
141-
firebase.initializeApp(fbConfig)
142-
143-
// Add redux Firebase to compose
144-
const createStoreWithFirebase = createStore(
145-
rootReducer,
146-
initialState,
147-
compose(
148-
reactReduxFirebase(firebase, rrfConfig),
149-
applyMiddleware(thunk)
150-
)
151-
)
152-
153-
// Create store with reducers and initial state
154-
const store = createStoreWithFirebase(rootReducer, initialState)
155-
156-
// Listen for auth ready (promise available on store thanks to attachAuthIsReady: true config option)
157-
store.firebaseAuthIsReady.then(() => {
158-
console.log('Auth has loaded') // eslint-disable-line no-console
159-
})
160-
return store;
161-
}
162-
```
163-
164-
In order for this to work, the promise must know the name of the location within redux that the state is being stored, which is the function of the `firebaseStateName` config option. By default the `firebaseStateName` parameter is `'firebase'` to match the getting started guide. If you are storing your firebase state under a different place within redux (i.e. the name given to the `firebaseStateReducer`) such as `'firebaseState'` you must pass that name as `firebaseStateName` in your config.
165-
166-
#### Custom Auth Ready Logic
167-
168-
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.
169-
170-
Here is an example showing the default logic:
171-
172-
```js
173-
import { get } from 'lodash'
174-
175-
const config = {
176-
authIsReady: (store, firebaseStateName) => new Promise((resolve) => {
177-
const firebaseAuthState = && state[firebaseStateName].auth
178-
if (get(store.getState(), `${firebaseStateName}.auth.isLoaded`)) {
179-
resolve()
180-
} else {
181-
const unsubscribe = store.subscribe(() => {
182-
if (get(store.getState(), `${firebaseStateName}.auth.isLoaded`)) {
183-
unsubscribe()
184-
resolve()
185-
}
186-
})
187-
}
188-
})
189-
}
190-
```
191-
192117
## List of Online Users (Presence)
193118

194119
Presence keeps a list of which users are currently online as well as a history of all user sessions.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import { ExtendedFirebaseInstance, useFirebase} from "react-redux-firebase";
3+
4+
function AddTodo() {
5+
const firebase: ExtendedFirebaseInstance = useFirebase();
6+
function handleAddClick() {
7+
firebase.push("todos", { done: false, text: "Example todo" });
8+
}
9+
return (
10+
<div className="Add Todo">
11+
<button onClick={handleAddClick}>Add Todo</button>
12+
</div>
13+
);
14+
}
15+
16+
export default AddTodo;
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from 'react'
2-
import { Provider } from 'react-redux'
3-
import Home from './Home'
4-
import configureStore from './store'
5-
import { ReactReduxFirebaseProvider } from 'react-redux-firebase';
6-
import firebase from 'firebase/app'
7-
import 'firebase/auth'
8-
import 'firebase/database'
9-
import 'firebase/firestore' // make sure you add this for firestore
10-
import { firebase as fbConfig, reduxFirebase as rfConfig } from './config'
1+
import firebase from "firebase/app";
2+
import "firebase/auth";
3+
import "firebase/database";
4+
import "firebase/firestore"; // make sure you add this for firestore
5+
import React from "react";
6+
import { Provider } from "react-redux";
7+
import { ReactReduxFirebaseProvider } from "react-redux-firebase";
8+
import { firebase as fbConfig, reduxFirebase as rfConfig } from "./config";
9+
import Home from "./Home";
10+
import configureStore from "./store";
1111

12-
const initialState = {}
13-
const store = configureStore(initialState)
12+
const initialState = {};
13+
const store = configureStore(initialState);
1414
// Initialize Firebase instance
15-
firebase.initializeApp(fbConfig)
15+
firebase.initializeApp(fbConfig);
1616

1717
export default () => (
1818
<Provider store={store}>
@@ -23,5 +23,5 @@ export default () => (
2323
<Home />
2424
</ReactReduxFirebaseProvider>
2525
</Provider>
26-
)
26+
);
2727

examples/complete/typescript/src/Home.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from "react";
2-
import { ExtendedFirebaseInstance, useFirebase} from "react-redux-firebase";
2+
import AddTodo from "./AddTodo";
33
import "./App.css";
44
import logo from "./logo.svg";
55

66
function Home() {
7-
const firebase: ExtendedFirebaseInstance = useFirebase();
8-
firebase.push;
97
return (
108
<div className="Home">
119
<header className="App-header">
@@ -21,6 +19,7 @@ function Home() {
2119
>
2220
Learn React
2321
</a>
22+
<AddTodo />
2423
</header>
2524
</div>
2625
);

src/createFirebaseInstance.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
492492

493493
/**
494494
* @name signInWithPhoneNumber
495-
* Asynchronously signs in using a phone number. This method
495+
* @description Asynchronously signs in using a phone number. This method
496496
* sends a code via SMS to the given phone number, and returns a modified
497497
* firebase.auth.ConfirmationResult. The `confirm` method
498498
* authenticates and does profile handling.
@@ -501,7 +501,7 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
501501
*/
502502
/**
503503
* @name initializeAuth
504-
* Initialize auth to work with build in profile support
504+
* @description Initialize auth to work with build in profile support
505505
*/
506506
const actionCreators = mapWithFirebaseAndDispatch(
507507
firebase,
@@ -518,22 +518,22 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
518518

519519
/**
520520
* @name ref
521-
* Firebase ref function
521+
* @description Firebase ref function
522522
* @return {firebase.database.Reference}
523523
*/
524524
/**
525525
* @name database
526-
* Firebase database service instance including all Firebase storage methods
526+
* @description Firebase database service instance including all Firebase storage methods
527527
* @return {firebase.database.Database} Firebase database service
528528
*/
529529
/**
530530
* @name storage
531-
* Firebase storage service instance including all Firebase storage methods
531+
* @description Firebase storage service instance including all Firebase storage methods
532532
* @return {firebase.database.Storage} Firebase storage service
533533
*/
534534
/**
535535
* @name auth
536-
* Firebase auth service instance including all Firebase auth methods
536+
* @description Firebase auth service instance including all Firebase auth methods
537537
* @return {firebase.database.Auth}
538538
*/
539539
return Object.assign(firebase, {

0 commit comments

Comments
 (0)