Skip to content

Commit 400d7ee

Browse files
committed
Merge branch 'master' of github.com:fullstackreact/react-native-firestack
* 'master' of github.com:fullstackreact/react-native-firestack: Fixed setPersistence always enabled Prevent race condition with listenForAuth
2 parents 3c9ce62 + 583272c commit 400d7ee

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

ios/Firestack/FirestackAuth.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
@interface FirestackAuth : RCTEventEmitter <RCTBridgeModule> {
1717
FIRAuthStateDidChangeListenerHandle authListenerHandle;
18+
Boolean listening;
1819
}
1920

2021
@end

ios/Firestack/FirestackAuth.m

+3-6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ @implementation FirestackAuth
130130

131131
RCT_EXPORT_METHOD(listenForAuth)
132132
{
133+
self->listening = true;
133134
self->authListenerHandle =
134135
[[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth,
135136
FIRUser *_Nullable user) {
@@ -174,15 +175,11 @@ @implementation FirestackAuth
174175
{
175176
if (self->authListenerHandle != nil) {
176177
[[FIRAuth auth] removeAuthStateDidChangeListener:self->authListenerHandle];
178+
self->listening = false;
177179
callback(@[[NSNull null]]);
178180
}
179181
}
180182

181-
// Helper
182-
- (Boolean) listeningForAuth {
183-
return (self->authListenerHandle != nil);
184-
}
185-
186183
RCT_EXPORT_METHOD(getCurrentUser:(RCTResponseSenderBlock)callback)
187184
{
188185
FIRUser *user = [FIRAuth auth].currentUser;
@@ -496,7 +493,7 @@ - (void) sendJSEvent:(NSString *)title
496493
props:(NSDictionary *)props
497494
{
498495
@try {
499-
if ([self listeningForAuth]) {
496+
if (self->listening) {
500497
[self sendEventWithName:title
501498
body:props];
502499
}

lib/modules/database.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ export class Database extends Base {
367367
}
368368

369369
setPersistence(enable=true) {
370-
this.persistenceEnabled = enable;
371370
let promise;
372371
if (this.persistenceEnabled !== enable) {
373372
this.log.debug(`${enable ? 'Enabling' : 'Disabling'} persistence`);
374373
promise = this.whenReady(promisify('enablePersistence', FirestackDatabase)(enable));
374+
this.persistenceEnabled = enable;
375375
} else {
376376
promise = this.whenReady(Promise.resolve({status: "Already enabled"}))
377377
}

0 commit comments

Comments
 (0)