Skip to content

Commit ebde245

Browse files
authored
feat(auth): exposing handleRedirectResult for react-firebaseui - @dirathea
2 parents d27b631 + c94f498 commit ebde245

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

docs/recipes/auth.md

Lines changed: 63 additions & 0 deletions
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

src/createFirebaseInstance.js

Lines changed: 10 additions & 0 deletions
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,

0 commit comments

Comments
 (0)