File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments