Xavier Bauquet
Xavier Bauquet

Reputation: 730

Firebase Auth error: 'data parameter is nil' calling getIDTokenForcingRefresh

I'm using Firebase UI for iOS to sign in with google or facebook into my app. I just updated the pods to this versions:

Installing FBSDKCoreKit 4.31.1 (was 4.31.0)
Installing FBSDKLoginKit 4.31.1 (was 4.31.0)
Installing Fabric 1.7.6 (was 1.7.5)
Installing Firebase 4.12.0 (was 4.9.0)
Installing FirebaseAnalytics 4.1.0 (was 4.0.9)
Installing FirebaseAuth 4.6.0 (was 4.4.3)
Installing FirebaseCore 4.0.19 (was 4.0.15)
Installing FirebaseInstanceID 2.0.10 (was 2.0.9)
Installing FirebaseMessaging 2.2.0 (was 2.1.0)
Installing FirebaseUI 4.5.5 (was 4.5.1)
Installing GTMSessionFetcher 1.1.15 (was 1.1.14)

But now I get an error when calling getIDTokenForcingRefresh. Here is the error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

In this part of GTMSessionFetcher

- (void)invokeFetchCallbacksOnCallbackQueueWithData:(GTM_NULLABLE NSData *)data
                                              error:(GTM_NULLABLE NSError *)error {
  // Callbacks will be released in the method stopFetchReleasingCallbacks:
  GTMSessionFetcherCompletionHandler handler;
  @synchronized(self) {
    GTMSessionMonitorSynchronized(self);

    handler = _completionHandler;

    if (handler) {
      [self invokeOnCallbackQueueUnlessStopped:^{
        handler(data, error); // <-- Error appends here (data is nil)

        // Post a notification, primarily to allow code to collect responses for
        // testing.
        //
        // The observing code is not likely on the fetcher's callback
        // queue, so this posts explicitly to the main queue.
        NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
        if (data) {
          userInfo[kGTMSessionFetcherCompletionDataKey] = data;
        }
        if (error) {
          userInfo[kGTMSessionFetcherCompletionErrorKey] = error;
        }
        [self postNotificationOnMainThreadWithName:kGTMSessionFetcherCompletionInvokedNotification
                                          userInfo:userInfo
                                      requireAsync:NO];
      }];
    }
  }  // @synchronized(self)
}

And here is my code:

func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
        if let error = error {
            print(error)
            return
        }
        if let authDataResultUser = authDataResult?.user {
            authDataResultUser.getIDTokenForcingRefresh(true) { idToken, error in
                if error != nil {
                    print()
                    return
                }
                // .....
            }
        }
    }

Upvotes: 2

Views: 482

Answers (2)

JaredH
JaredH

Reputation: 2398

This is a bug with the Firebase iOS SDK and the issue has now been fixed. The fix will be released as 4.12.1 as per here. Link also contains instructions for workarounds until release is out.

Alternatively, if you want to your Pods:

I'm able to successfully use the below versions in my project. I had a bit of trouble pegging all the specific versions of the Firebase libraries in my Podfile and had to use the .lock file instead. I'm able to successfully use the below versions in my project. If you run pod install, Cocoapods will resolve dependencies for whatever is not in your Podfile.lock. As per Cocoapods docs,

For pods listed in the Podfile.lock, it downloads the explicit version listed in the Podfile.lock without trying to check if a newer version is available

My suggestion is to try replacing references to Firebase in your Podfile.lock with the following, until this issue is resolved by the Firebase SDK team:

PODS:
  - Firebase/Auth (4.8.2):
    - Firebase/Core
    - FirebaseAuth (= 4.4.2)
  - Firebase/Core (4.8.2):
    - FirebaseAnalytics (= 4.0.9)
    - FirebaseCore (= 4.0.14)
  - Firebase/Database (4.8.2):
    - Firebase/Core
    - FirebaseDatabase (= 4.1.4)
  - Firebase/DynamicLinks (4.8.2):
    - Firebase/Core
    - FirebaseDynamicLinks (= 2.3.2)
  - Firebase/Firestore (4.8.2):
    - Firebase/Core
    - FirebaseFirestore (= 0.10.0)
  - Firebase/Messaging (4.8.2):
    - Firebase/Core
    - FirebaseMessaging (= 2.0.8)
  - Firebase/Performance (4.8.2):
    - Firebase/Core
    - FirebasePerformance (= 1.1.1)
  - Firebase/Storage (4.8.2):
    - Firebase/Core
    - FirebaseStorage (= 2.1.2)
  - FirebaseAnalytics (4.0.9):
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - nanopb (~> 0.3)
  - FirebaseAuth (4.4.2):
    - FirebaseAnalytics (~> 4.0)
    - "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
    - GTMSessionFetcher/Core (~> 1.1)
  - FirebaseCore (4.0.14):
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
  - FirebaseDatabase (4.1.4):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - leveldb-library (~> 1.18)
  - FirebaseDynamicLinks (2.3.2):
    - FirebaseAnalytics (~> 4.0)
  - FirebaseFirestore (0.10.0):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - gRPC-ProtoRPC (~> 1.0)
    - leveldb-library (~> 1.18)
    - Protobuf (~> 3.1)
  - FirebaseInstanceID (2.0.8):
    - FirebaseCore (~> 4.0)
  - FirebaseMessaging (2.0.8):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - Protobuf (~> 3.1)
  - FirebasePerformance (1.1.1):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - FirebaseSwizzlingUtilities (~> 1.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - GTMSessionFetcher/Core (~> 1.1)
    - Protobuf (~> 3.1)
  - FirebaseStorage (2.1.2):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - GTMSessionFetcher/Core (~> 1.1)
  - FirebaseSwizzlingUtilities (1.0.0)
  - FirebaseUI (4.5.1):
    - FirebaseUI/All (= 4.5.1)
  - FirebaseUI/All (4.5.1):
    - FirebaseUI/Auth
    - FirebaseUI/Database
    - FirebaseUI/Facebook
    - FirebaseUI/Firestore
    - FirebaseUI/Google
    - FirebaseUI/Phone
    - FirebaseUI/Storage
    - FirebaseUI/Twitter
  - FirebaseUI/Auth (4.5.1):
    - Firebase/Auth (~> 4.2)
  - FirebaseUI/Database (4.5.1):
    - Firebase/Database (~> 4.0)
  - FirebaseUI/Facebook (4.5.1):
    - FBSDKLoginKit (~> 4.0)
    - FirebaseUI/Auth
  - FirebaseUI/Firestore (4.5.1):
    - Firebase/Firestore
  - FirebaseUI/Google (4.5.1):
    - FirebaseUI/Auth
    - GoogleSignIn (~> 4.0)
  - FirebaseUI/Phone (4.5.1):
    - FirebaseUI/Auth
  - FirebaseUI/Storage (4.5.1):
    - Firebase/Storage (~> 4.0)
    - SDWebImage (~> 4.0)
  - FirebaseUI/Twitter (4.5.1):
    - FirebaseUI/Auth
    - TwitterKit (~> 3.0)

Upvotes: 1

Xavier Bauquet
Xavier Bauquet

Reputation: 730

It seems like Firebase found a wrokaround. If you run pod install a few library are downgraded:

Installing Firebase 4.5.0 (was 4.12.0)
Installing FirebaseAnalytics 4.0.4 (was 4.1.0)
Installing FirebaseAuth 4.3.1 (was 4.6.0)
Installing FirebaseCore 4.0.10 (was 4.0.19)
Installing FirebaseMessaging 2.0.6 (was 2.2.0)

After that it's working again.

Upvotes: 0

Related Questions