Skip to content

Prevent race condition with listenForAuth (iOS) #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/Firestack/FirestackAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@interface FirestackAuth : RCTEventEmitter <RCTBridgeModule> {
FIRAuthStateDidChangeListenerHandle authListenerHandle;
Boolean listening;
}

@end
Expand Down
9 changes: 3 additions & 6 deletions ios/Firestack/FirestackAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ @implementation FirestackAuth

RCT_EXPORT_METHOD(listenForAuth)
{
self->listening = true;
self->authListenerHandle =
[[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth,
FIRUser *_Nullable user) {
Expand Down Expand Up @@ -174,15 +175,11 @@ @implementation FirestackAuth
{
if (self->authListenerHandle != nil) {
[[FIRAuth auth] removeAuthStateDidChangeListener:self->authListenerHandle];
self->listening = false;
callback(@[[NSNull null]]);
}
}

// Helper
- (Boolean) listeningForAuth {
return (self->authListenerHandle != nil);
}

RCT_EXPORT_METHOD(getCurrentUser:(RCTResponseSenderBlock)callback)
{
FIRUser *user = [FIRAuth auth].currentUser;
Expand Down Expand Up @@ -496,7 +493,7 @@ - (void) sendJSEvent:(NSString *)title
props:(NSDictionary *)props
{
@try {
if ([self listeningForAuth]) {
if (self->listening) {
[self sendEventWithName:title
body:props];
}
Expand Down