Skip to content

Commit 150a839

Browse files
author
Nicolas Garnier
committed
Better samples on the README: now uses the Firebase auth listener
1 parent 9d5ba74 commit 150a839

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ class SignInScreen extends React.Component {
110110
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
111111
firebase.auth.FacebookAuthProvider.PROVIDER_ID
112112
],
113-
// Sets the `signedIn` state property to `true` once signed in.
113+
// Avoid redirects after sign-in.
114114
callbacks: {
115-
signInSuccess: () => {
116-
this.setState({signedIn: true});
117-
return false; // Avoid redirects after sign-in.
118-
}
115+
signInSuccess: () => false
119116
}
120117
};
118+
119+
// Listen to the Firebase Auth state and set the local state.
120+
componentWillMount() {
121+
firebase.auth().onAuthStateChanged((user) => {
122+
this.setState({signedIn: !!user});
123+
});
124+
}
121125

122126
render() {
123127
if (!this.state.signedIn) {
@@ -132,7 +136,8 @@ class SignInScreen extends React.Component {
132136
return (
133137
<div>
134138
<h1>My App</h1>
135-
<p>Welcome! You are now signed-in!</p>
139+
<p>Welcome {firebase.auth().currentUser.displayName}! You are now signed-in!</p>
140+
<a onClick={() => firebase.auth().signOut()}>Sign-out</a>
136141
</div>
137142
);
138143
}

0 commit comments

Comments
 (0)