Skip to content

Update dependencies: 🔥 Firebase 8 and ⚛️ React 17 #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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