Skip to content

Commit 447cf37

Browse files
Vitalik Maymikehardy
Vitalik May
authored andcommitted
[IOS][BUGFIX][AUTHENTICATION] - fix crash w/2+ Firebase projects at same time (#2310)
* #2180 iOS bug fix: Collection was mutated while being enumerated * #2180 removed release of key arrays
1 parent 78cd643 commit 447cf37

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ios/RNFirebase/auth/RNFirebaseAuth.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ - (id)init {
4949
- (void)dealloc {
5050
DLog(@"RNFirebaseAuth:instance-destroyed");
5151

52-
for(NSString* key in authStateHandlers) {
52+
NSArray *authStateKeys = [authStateHandlers allKeys];
53+
for(NSString* key in authStateKeys) {
5354
FIRApp *firApp = [RNFirebaseUtil getApp:key];
5455
[[FIRAuth authWithApp:firApp] removeAuthStateDidChangeListener:[authStateHandlers valueForKey:key]];
5556
[authStateHandlers removeObjectForKey:key];
5657
}
5758

58-
for(NSString* key in idTokenHandlers) {
59+
NSArray *idTokenKeys = [idTokenHandlers allKeys];
60+
for(NSString* key in idTokenKeys) {
5961
FIRApp *firApp = [RNFirebaseUtil getApp:key];
6062
[[FIRAuth authWithApp:firApp] removeIDTokenDidChangeListener:[idTokenHandlers valueForKey:key]];
6163
[idTokenHandlers removeObjectForKey:key];
@@ -65,13 +67,15 @@ - (void)dealloc {
6567
- (void)invalidate {
6668
// dealloc sometimes is not called when app is reloaded.
6769

68-
for(NSString* key in authStateHandlers) {
70+
NSArray *authStateKeys = [authStateHandlers allKeys];
71+
for(NSString* key in authStateKeys) {
6972
FIRApp *firApp = [RNFirebaseUtil getApp:key];
7073
[[FIRAuth authWithApp:firApp] removeAuthStateDidChangeListener:[authStateHandlers valueForKey:key]];
7174
[authStateHandlers removeObjectForKey:key];
7275
}
7376

74-
for(NSString* key in idTokenHandlers) {
77+
NSArray *idTokenKeys = [idTokenHandlers allKeys];
78+
for(NSString* key in idTokenKeys) {
7579
FIRApp *firApp = [RNFirebaseUtil getApp:key];
7680
[[FIRAuth authWithApp:firApp] removeIDTokenDidChangeListener:[idTokenHandlers valueForKey:key]];
7781
[idTokenHandlers removeObjectForKey:key];

0 commit comments

Comments
 (0)