@@ -35,6 +35,7 @@ let fbCallbackManager = null;
3535const GOOGLE_SIGNIN_INTENT_ID = 123 ;
3636const REQUEST_INVITE_INTENT_ID = 48 ;
3737
38+ const authEnabled = lazy ( ( ) => typeof ( com . google . firebase . auth ) !== "undefined" ) ;
3839const messagingEnabled = lazy ( ( ) => typeof ( com . google . firebase . messaging ) !== "undefined" ) ;
3940const dynamicLinksEnabled = lazy ( ( ) => typeof ( com . google . firebase . dynamiclinks ) !== "undefined" ) ;
4041
@@ -298,33 +299,35 @@ firebase.init = arg => {
298299 }
299300 }
300301
301- const firebaseAuth = com . google . firebase . auth . FirebaseAuth . getInstance ( ) ;
302+ if ( authEnabled ( ) ) {
303+ const firebaseAuth = com . google . firebase . auth . FirebaseAuth . getInstance ( ) ;
302304
303- if ( arg . onAuthStateChanged ) {
304- firebase . authStateListener = new com . google . firebase . auth . FirebaseAuth . AuthStateListener ( {
305- onAuthStateChanged : fbAuth => {
306- const user = fbAuth . getCurrentUser ( ) ;
307- arg . onAuthStateChanged ( {
308- loggedIn : user !== null ,
309- user : toLoginResult ( user )
310- } ) ;
311- }
312- } ) ;
313- firebaseAuth . addAuthStateListener ( firebase . authStateListener ) ;
314- }
305+ if ( arg . onAuthStateChanged ) {
306+ firebase . authStateListener = new com . google . firebase . auth . FirebaseAuth . AuthStateListener ( {
307+ onAuthStateChanged : fbAuth => {
308+ const user = fbAuth . getCurrentUser ( ) ;
309+ arg . onAuthStateChanged ( {
310+ loggedIn : user !== null ,
311+ user : toLoginResult ( user )
312+ } ) ;
313+ }
314+ } ) ;
315+ firebaseAuth . addAuthStateListener ( firebase . authStateListener ) ;
316+ }
315317
316- // Listen to auth state changes
317- if ( ! firebase . authStateListener ) {
318- firebase . authStateListener = new com . google . firebase . auth . FirebaseAuth . AuthStateListener ( {
319- onAuthStateChanged : fbAuth => {
320- const user = fbAuth . getCurrentUser ( ) ;
321- firebase . notifyAuthStateListeners ( {
322- loggedIn : user !== null ,
323- user : toLoginResult ( user )
324- } ) ;
325- }
326- } ) ;
327- firebaseAuth . addAuthStateListener ( firebase . authStateListener ) ;
318+ // Listen to auth state changes
319+ if ( ! firebase . authStateListener ) {
320+ firebase . authStateListener = new com . google . firebase . auth . FirebaseAuth . AuthStateListener ( {
321+ onAuthStateChanged : fbAuth => {
322+ const user = fbAuth . getCurrentUser ( ) ;
323+ firebase . notifyAuthStateListeners ( {
324+ loggedIn : user !== null ,
325+ user : toLoginResult ( user )
326+ } ) ;
327+ }
328+ } ) ;
329+ firebaseAuth . addAuthStateListener ( firebase . authStateListener ) ;
330+ }
328331 }
329332
330333 // Firebase notifications (FCM)
0 commit comments