diff --git a/ios/RNFirebase/auth/RNFirebaseAuth.h b/ios/RNFirebase/auth/RNFirebaseAuth.h index dd3fef7747b..e47ec98f564 100644 --- a/ios/RNFirebase/auth/RNFirebaseAuth.h +++ b/ios/RNFirebase/auth/RNFirebaseAuth.h @@ -6,6 +6,7 @@ #import #import #import +#import @interface RNFirebaseAuth : RCTEventEmitter {}; @end diff --git a/ios/RNFirebase/auth/RNFirebaseAuth.m b/ios/RNFirebase/auth/RNFirebaseAuth.m index 267ee30ee06..2246e165418 100644 --- a/ios/RNFirebase/auth/RNFirebaseAuth.m +++ b/ios/RNFirebase/auth/RNFirebaseAuth.m @@ -62,6 +62,22 @@ - (void)dealloc { } } +- (void)invalidate { + // dealloc sometimes is not called when app is reloaded. + + for(NSString* key in authStateHandlers) { + FIRApp *firApp = [RNFirebaseUtil getApp:key]; + [[FIRAuth authWithApp:firApp] removeAuthStateDidChangeListener:[authStateHandlers valueForKey:key]]; + [authStateHandlers removeObjectForKey:key]; + } + + for(NSString* key in idTokenHandlers) { + FIRApp *firApp = [RNFirebaseUtil getApp:key]; + [[FIRAuth authWithApp:firApp] removeIDTokenDidChangeListener:[idTokenHandlers valueForKey:key]]; + [idTokenHandlers removeObjectForKey:key]; + } +} + /** * addAuthStateListener *