aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--FirebaseFirestore.podspec1
-rw-r--r--Firestore/CHANGELOG.md1
-rw-r--r--Firestore/Source/Auth/FSTCredentialsProvider.m60
3 files changed, 33 insertions, 29 deletions
diff --git a/FirebaseFirestore.podspec b/FirebaseFirestore.podspec
index 6d1377c..bd3ee54 100644
--- a/FirebaseFirestore.podspec
+++ b/FirebaseFirestore.podspec
@@ -47,7 +47,6 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
s.public_header_files = 'Firestore/Source/Public/*.h'
s.ios.dependency 'FirebaseAnalytics', '~> 4.0'
- s.dependency 'FirebaseAuth', '~> 4.3'
s.dependency 'FirebaseCore', '~> 4.0'
s.dependency 'gRPC-ProtoRPC', '~> 1.0'
s.dependency 'leveldb-library', '~> 1.18'
diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md
index 0aba04e..884af45 100644
--- a/Firestore/CHANGELOG.md
+++ b/Firestore/CHANGELOG.md
@@ -1,4 +1,5 @@
# Unreleased
+- [changed] Firestore no longer has a direct dependency on FirebaseAuth.
# v0.9.3
- [changed] Improved performance loading documents matching a query.
diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.m b/Firestore/Source/Auth/FSTCredentialsProvider.m
index 7aa3671..57d79cb 100644
--- a/Firestore/Source/Auth/FSTCredentialsProvider.m
+++ b/Firestore/Source/Auth/FSTCredentialsProvider.m
@@ -16,8 +16,6 @@
#import "Firestore/Source/Auth/FSTCredentialsProvider.h"
-#import <FirebaseAuth/FIRAuth.h>
-#import <FirebaseAuth/FIRUser.h>
#import <FirebaseCore/FIRApp.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <GRPCClient/GRPCCall.h>
@@ -43,17 +41,12 @@ NS_ASSUME_NONNULL_BEGIN
@end
#pragma mark - FSTFirebaseCredentialsProvider
-// TODO(mikelehen): Currently, we have a strong dependency on FIRAuth but we should ideally use
-// only internal APIs on FIRApp instead. However, currently the FIRApp internal APIs don't expose
-// the uid of the current user and don't expose an auth state change listener. So we use FIRAuth.
@interface FSTFirebaseCredentialsProvider ()
@property(nonatomic, strong, readonly) FIRApp *app;
-@property(nonatomic, strong, readonly) FIRAuth *auth;
/** Handle used to stop receiving auth changes once userChangeListener is removed. */
-@property(nonatomic, strong, nullable, readwrite)
- FIRAuthStateDidChangeListenerHandle authListenerHandle;
+@property(nonatomic, strong, nullable, readwrite) id<NSObject> authListenerHandle;
/** The current user as reported to us via our AuthStateDidChangeListener. */
@property(nonatomic, strong, nonnull, readwrite) FSTUser *currentUser;
@@ -74,28 +67,40 @@ NS_ASSUME_NONNULL_BEGIN
self = [super init];
if (self) {
_app = app;
- _auth = [FIRAuth authWithApp:app];
- _currentUser = [[FSTUser alloc] initWithUID:self.auth.currentUser.uid];
+ _currentUser = [[FSTUser alloc] initWithUID:[self.app getUID]];
_userCounter = 0;
// Register for user changes so that we can internally track the current user.
FSTWeakify(self);
- _authListenerHandle = [self.auth addAuthStateDidChangeListener:^(FIRAuth *auth, FIRUser *user) {
- FSTStrongify(self);
- if (self) {
- @synchronized(self) {
- FSTUser *newUser = [[FSTUser alloc] initWithUID:user.uid];
- if (![newUser isEqual:self.currentUser]) {
- self.currentUser = newUser;
- self.userCounter++;
- FSTVoidUserBlock listenerBlock = self.userChangeListener;
- if (listenerBlock) {
- listenerBlock(self.currentUser);
- }
- }
- }
- }
- }];
+ _authListenerHandle = [[NSNotificationCenter defaultCenter]
+ addObserverForName:FIRAuthStateDidChangeInternalNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *notification) {
+ FSTStrongify(self);
+ if (self) {
+ @synchronized(self) {
+ NSDictionary *userInfo = notification.userInfo;
+
+ // ensure we're only notifiying for the current app.
+ FIRApp *notifiedApp = userInfo[FIRAuthStateDidChangeInternalNotificationAppKey];
+ if (![self.app isEqual:notifiedApp]) {
+ return;
+ }
+
+ NSString *userID = userInfo[FIRAuthStateDidChangeInternalNotificationUIDKey];
+ FSTUser *newUser = [[FSTUser alloc] initWithUID:userID];
+ if (![newUser isEqual:self.currentUser]) {
+ self.currentUser = newUser;
+ self.userCounter++;
+ FSTVoidUserBlock listenerBlock = self.userChangeListener;
+ if (listenerBlock) {
+ listenerBlock(self.currentUser);
+ }
+ }
+ }
+ }
+ }];
}
return self;
}
@@ -140,8 +145,7 @@ NS_ASSUME_NONNULL_BEGIN
} else {
FSTAssert(self.authListenerHandle, @"UserChangeListener removed twice!");
FSTAssert(_userChangeListener, @"UserChangeListener removed without being set!");
- [self.auth removeAuthStateDidChangeListener:self.authListenerHandle];
-
+ [[NSNotificationCenter defaultCenter] removeObserver:self.authListenerHandle];
self.authListenerHandle = nil;
}
_userChangeListener = block;