Skip to content

Commit

Permalink
Update dependencies: 🔥 Firebase 8 and ⚛️ React 17 (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuleatt authored Apr 26, 2021
1 parent 79b8d34 commit 11cf289
Show file tree
Hide file tree
Showing 10 changed files with 7,115 additions and 5,408 deletions.
126 changes: 58 additions & 68 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ const uiConfig = {
// We will display Google and Facebook as auth providers.
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID
]
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
],
};

class SignInScreen extends React.Component {
render() {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
function SignInScreen() {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} />
</div>
);
}

export default SignInScreen
```

### Using `FirebaseAuth` with local state.
### Using `StyledFirebaseAuth` with local state.

Below is an example on how to use `FirebaseAuth` with a state change upon sign-in:
Below is an example on how to use `StyledFirebaseAuth` with a state change upon sign-in:

```js
// Import FirebaseAuth and firebase.
import React from 'react';
import React, { useEffect, useState } from 'react';
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from 'firebase';

Expand All @@ -102,59 +102,51 @@ const config = {
};
firebase.initializeApp(config);

class SignInScreen extends React.Component {

// The component's Local state.
state = {
isSignedIn: false // Local signed-in state.
};

// Configure FirebaseUI.
uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: 'popup',
// We will display Google and Facebook as auth providers.
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID
],
callbacks: {
// Avoid redirects after sign-in.
signInSuccessWithAuthResult: () => false
}
};
// Configure FirebaseUI.
const uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: 'popup',
// We will display Google and Facebook as auth providers.
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID
],
callbacks: {
// Avoid redirects after sign-in.
signInSuccessWithAuthResult: () => false,
},
};

function SignInScreen() {
const [isSignedIn, setIsSignedIn] = useState(false); // Local signed-in state.

// Listen to the Firebase Auth state and set the local state.
componentDidMount() {
this.unregisterAuthObserver = firebase.auth().onAuthStateChanged(
(user) => this.setState({isSignedIn: !!user})
);
}

// Make sure we un-register Firebase observers when the component unmounts.
componentWillUnmount() {
this.unregisterAuthObserver();
}

render() {
if (!this.state.isSignedIn) {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
useEffect(() => {
const unregisterAuthObserver = firebase.auth().onAuthStateChanged(user => {
setIsSignedIn(!!user);
});
return () => unregisterAuthObserver(); // Make sure we un-register Firebase observers when the component unmounts.
}, []);

if (!isSignedIn) {
return (
<div>
<h1>My App</h1>
<p>Welcome {firebase.auth().currentUser.displayName}! You are now signed-in!</p>
<a onClick={() => firebase.auth().signOut()}>Sign-out</a>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} />
</div>
);
}
return (
<div>
<h1>My App</h1>
<p>Welcome {firebase.auth().currentUser.displayName}! You are now signed-in!</p>
<a onClick={() => firebase.auth().signOut()}>Sign-out</a>
</div>
);
}

export default SignInScreen;
```

### Accessing the FirebaseUI instance
Expand All @@ -165,15 +157,13 @@ To do this you can pass a `uiCallback` callback function that wil be passed the
```js
// ...

render() {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiCallback={ui => ui.disableAutoSignIn()} uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiCallback={ui => ui.disableAutoSignIn()} uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
```


Expand Down
2 changes: 1 addition & 1 deletion dist/StyledFirebaseAuth.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/StyledFirebaseAuth.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 11cf289

Please sign in to comment.