@@ -48,15 +48,16 @@ Below is an example on how to use `FirebaseAuth` with a redirect upon sign-in:
4848// Import FirebaseAuth and firebase.
4949import React from ' react' ;
5050import StyledFirebaseAuth from ' react-firebaseui/StyledFirebaseAuth' ;
51- import firebase from ' firebase' ;
51+ import { initializeApp } from ' firebase/app' ;
52+ import { getAuth , EmailAuthProvider , GoogleAuthProvider } from ' firebase/auth' ;
5253
5354// Configure Firebase.
5455const config = {
5556 apiKey: ' AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM' ,
5657 authDomain: ' myproject-1234.firebaseapp.com' ,
5758 // ...
5859};
59- firebase . initializeApp (config );
60+ const firebaseApp = initializeApp (firebaseConfig );
6061
6162// Configure FirebaseUI.
6263const uiConfig = {
@@ -66,17 +67,19 @@ const uiConfig = {
6667 signInSuccessUrl: ' /signedIn' ,
6768 // We will display Google and Facebook as auth providers.
6869 signInOptions: [
69- firebase . auth . GoogleAuthProvider .PROVIDER_ID ,
70- firebase . auth . FacebookAuthProvider .PROVIDER_ID ,
70+ GoogleAuthProvider .PROVIDER_ID ,
71+ FacebookAuthProvider .PROVIDER_ID ,
7172 ],
7273};
7374
7475function SignInScreen () {
76+ const auth = getAuth (firebaseApp)
77+
7578 return (
7679 < div>
7780 < h1> My App< / h1>
7881 < p> Please sign- in: < / p>
79- < StyledFirebaseAuth uiConfig= {uiConfig} firebaseAuth= {firebase . auth () } / >
82+ < StyledFirebaseAuth uiConfig= {uiConfig} firebaseAuth= {auth} / >
8083 < / div>
8184 );
8285}
@@ -92,24 +95,25 @@ Below is an example on how to use `StyledFirebaseAuth` with a state change upon
9295// Import FirebaseAuth and firebase.
9396import React , { useEffect , useState } from ' react' ;
9497import StyledFirebaseAuth from ' react-firebaseui/StyledFirebaseAuth' ;
95- import firebase from ' firebase' ;
98+ import { initializeApp } from ' firebase/app' ;
99+ import { getAuth , onAuthStateChanged , signOut , EmailAuthProvider , GoogleAuthProvider } from ' firebase/auth' ;
96100
97101// Configure Firebase.
98102const config = {
99103 apiKey: ' AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM' ,
100104 authDomain: ' myproject-1234.firebaseapp.com' ,
101105 // ...
102106};
103- firebase . initializeApp (config );
107+ const firebaseApp = initializeApp (firebaseConfig );
104108
105109// Configure FirebaseUI.
106110const uiConfig = {
107111 // Popup signin flow rather than redirect flow.
108112 signInFlow: ' popup' ,
109113 // We will display Google and Facebook as auth providers.
110114 signInOptions: [
111- firebase . auth . GoogleAuthProvider .PROVIDER_ID ,
112- firebase . auth . FacebookAuthProvider .PROVIDER_ID
115+ GoogleAuthProvider .PROVIDER_ID ,
116+ FacebookAuthProvider .PROVIDER_ID
113117 ],
114118 callbacks: {
115119 // Avoid redirects after sign-in.
@@ -118,11 +122,12 @@ const uiConfig = {
118122};
119123
120124function SignInScreen () {
125+ const auth = getAuth (firebaseApp);
121126 const [isSignedIn , setIsSignedIn ] = useState (false ); // Local signed-in state.
122127
123128 // Listen to the Firebase Auth state and set the local state.
124129 useEffect (() => {
125- const unregisterAuthObserver = firebase . auth (). onAuthStateChanged (user => {
130+ const unregisterAuthObserver = onAuthStateChanged (auth, user => {
126131 setIsSignedIn (!! user);
127132 });
128133 return () => unregisterAuthObserver (); // Make sure we un-register Firebase observers when the component unmounts.
@@ -133,15 +138,15 @@ function SignInScreen() {
133138 < div>
134139 < h1> My App< / h1>
135140 < p> Please sign- in: < / p>
136- < StyledFirebaseAuth uiConfig= {uiConfig} firebaseAuth= {firebase . auth () } / >
141+ < StyledFirebaseAuth uiConfig= {uiConfig} firebaseAuth= {auth} / >
137142 < / div>
138143 );
139144 }
140145 return (
141146 < div>
142147 < h1> My App< / h1>
143- < p> Welcome {firebase . auth () .currentUser .displayName }! You are now signed- in ! < / p>
144- < a onClick= {() => firebase . auth (). signOut ()}> Sign- out< / a>
148+ < p> Welcome {auth .currentUser .displayName }! You are now signed- in ! < / p>
149+ < a onClick= {() => signOut (auth )}> Sign- out< / a>
145150 < / div>
146151 );
147152}
@@ -161,7 +166,7 @@ return (
161166 < div>
162167 < h1> My App< / h1>
163168 < p> Please sign- in: < / p>
164- < StyledFirebaseAuth uiCallback= {ui => ui .disableAutoSignIn ()} uiConfig= {uiConfig} firebaseAuth= {firebase . auth () }/ >
169+ < StyledFirebaseAuth uiCallback= {ui => ui .disableAutoSignIn ()} uiConfig= {uiConfig} firebaseAuth= {auth}/ >
165170 < / div>
166171);
167172```
0 commit comments