Skip to content

Commit c1d9d7e

Browse files
authored
v3.0.0-alpha.6
* feat(auth): exposing handleRedirectResult for react-firebaseui - prescottprue#608 - @dirathea * fix(firestoreConnect): fix invalid proptypes - prescottprue#611 & [redux-firestore 165](prescottprue/redux-firestore#165)
2 parents 4f7e6a5 + ebde245 commit c1d9d7e

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

docs/recipes/auth.md

+63
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,69 @@ export default compose(
5151
)(LoginPage)
5252
```
5353

54+
## Firebase UI React
55+
56+
Here is an example of a component that shows a usage of [Firebase UI](https://firebase.google.com/docs/auth/web/firebaseui), especially their [react component](https://github.com/firebase/firebaseui-web-react) and integrate the flow with this library:
57+
58+
```js
59+
import React from 'react'
60+
import PropTypes from 'prop-types'
61+
import { compose } from 'redux'
62+
import { connect } from 'react-redux'
63+
import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase'
64+
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
65+
// import { withRouter } from 'react-router-dom'; // if you use react-router
66+
// import GoogleButton from 'react-google-button' // optional
67+
68+
export const LoginPage = ({
69+
firebase,
70+
auth,
71+
//history if you use react-router
72+
}) => (
73+
<div className={classes.container}>
74+
<StyledFirebaseAuth
75+
uiConfig={{
76+
signInFlow: 'popup',
77+
signInSuccessUrl: '/signedIn',
78+
signInOptions: [this.props.firebase.auth.GoogleAuthProvider.PROVIDER_ID],
79+
callbacks: {
80+
signInSuccessWithAuthResult: (authResult, redirectUrl) => {
81+
firebase.handleRedirectResult(authResult).then(() => {
82+
// history.push(redirectUrl); if you use react router to redirect
83+
});
84+
return false;
85+
},
86+
},
87+
}}
88+
firebaseAuth={firebase.auth()}
89+
/>
90+
<div>
91+
<h2>Auth</h2>
92+
{
93+
!isLoaded(auth)
94+
? <span>Loading...</span>
95+
: isEmpty(auth)
96+
? <span>Not Authed</span>
97+
: <pre>{JSON.stringify(auth, null, 2)}</pre>
98+
}
99+
</div>
100+
</div>
101+
)
102+
103+
LoginPage.propTypes = {
104+
firebase: PropTypes.shape({
105+
handleRedirectResult: PropTypes.func.isRequired
106+
}),
107+
auth: PropTypes.object
108+
}
109+
110+
export default compose(
111+
//withRouter, if you use react router to redirect
112+
firebaseConnect(), // withFirebase can also be used
113+
connect(({ firebase: { auth } }) => ({ auth }))
114+
)(LoginPage)
115+
```
116+
54117

55118
## Wait For Auth To Be Ready
56119

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "3.0.0-alpha.5",
3+
"version": "3.0.0-alpha.6",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/createFirebaseInstance.js

+10
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
358358
const login = credentials =>
359359
authActions.login(dispatch, firebase, credentials)
360360

361+
/**
362+
* @description Logs user into Firebase using external. For examples, visit the
363+
* [auth section](/docs/recipes/auth.md)
364+
* @param {Object} authData - Auth data from Firebase's getRedirectResult
365+
* @return {Promise} Containing user's profile
366+
*/
367+
const handleRedirectResult = authData =>
368+
authActions.handleRedirectResult(dispatch, firebase, authData)
369+
361370
/**
362371
* @description Logs user out of Firebase and empties firebase state from
363372
* redux store
@@ -512,6 +521,7 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
512521
update,
513522
updateWithMeta,
514523
login,
524+
handleRedirectResult,
515525
logout,
516526
updateAuth,
517527
updateEmail,

src/firestoreConnect.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isEqual, some, filter } from 'lodash'
44
import hoistStatics from 'hoist-non-react-statics'
55
import { createCallable, wrapDisplayName } from './utils'
66
import ReduxFirestoreContext from './ReduxFirestoreContext'
7+
import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
78

89
/**
910
* @name createFirestoreConnect
@@ -87,27 +88,35 @@ export const createFirestoreConnect = (storeKey = 'store') => (
8788
}
8889

8990
FirestoreConnectWrapped.propTypes = {
90-
dispatch: PropTypes.func,
91+
dispatch: PropTypes.func.isRequired,
9192
firebase: PropTypes.object,
9293
firestore: PropTypes.object
9394
}
9495

9596
const HoistedComp = hoistStatics(FirestoreConnectWrapped, WrappedComponent)
9697

9798
const FirestoreConnect = props => (
98-
<ReduxFirestoreContext.Consumer>
99-
{firestore => <HoistedComp firestore={firestore} {...props} />}
100-
</ReduxFirestoreContext.Consumer>
99+
<ReactReduxFirebaseContext.Consumer>
100+
{firebase => (
101+
<ReduxFirestoreContext.Consumer>
102+
{firestore => (
103+
<HoistedComp
104+
firestore={firestore}
105+
firebase={firebase}
106+
dispatch={firebase.dispatch}
107+
{...props}
108+
/>
109+
)}
110+
</ReduxFirestoreContext.Consumer>
111+
)}
112+
</ReactReduxFirebaseContext.Consumer>
101113
)
114+
102115
FirestoreConnect.displayName = wrapDisplayName(
103116
WrappedComponent,
104117
'FirestoreConnect'
105118
)
106119

107-
FirestoreConnect.propTypes = {
108-
dispatch: PropTypes.func.isRequired
109-
}
110-
111120
return FirestoreConnect
112121
}
113122

0 commit comments

Comments
 (0)