React-native-firebase: [Auth] currentUser.providerId is always 'firebase'

Created on 18 Dec 2018  路  2Comments  路  Source: invertase/react-native-firebase


Issue

When I logged in by Facebook or Google value of currentUser.providerId is always 'firebase'

currentUser: {
      phoneNumber: null,
      uid: '...',
      providerId: 'firebase',
      providerData: [
        {
          email: '...',
          photoURL: '...',
          providerId: 'facebook.com',
          uid: '...',
          displayName: '...'
        },
        {
          email: '...',
          photoURL: '...',
          providerId: 'google.com',
          uid: '...',
          displayName: '...'
        }
      ],
      displayName: '...',
      refreshToken: '...',
      email: '...',
      isAnonymous: false,
      metadata: {
        creationTime: 1545114510000,
        lastSignInTime: 1545114648000
      },
      emailVerified: true,
      photoURL: ''
    }

Project Files






iOS

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
platform :ios, '9.0'

target 'SayblakeApp' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # RN Pods
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge', # Include this for RN >= 0.47
    'RCTImage',
    'RCTGeolocation'
  ]
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  # Pods for SayblakeApp
  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'
  pod 'Firebase/Storage'
  pod 'Fabric', '~> 1.7.11'
  pod 'Crashlytics', '~> 3.10.7'
  pod 'Firebase/Performance'

  pod 'RNI18n', :path => '../node_modules/react-native-i18n'

  pod 'RNImageCropPicker', :path =>  '../node_modules/react-native-image-crop-picker'

  pod 'react-native-fast-image', :path => '../node_modules/react-native-fast-image'

  pod 'react-native-maps', :path => '../node_modules/react-native-maps'

  pod 'ReactNativePermissions', :path => '../node_modules/react-native-permissions'

  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

  pod 'FacebookSDK'
  pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'

  pod 'GoogleSignIn'
  pod 'RNGoogleSignin', :path => '../node_modules/react-native-google-signin'

  target 'SayblakeAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'React'
     target.remove_from_project
   end
 end
end

AppDelegate.m:

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <Firebase.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import <RNGoogleSignin/RNGoogleSignin.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                               moduleName:@"SayblakeApp"
                                               initialProperties:nil
                                               launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  [FIRApp configure];
  [[FBSDKApplicationDelegate sharedInstance] application:application
                                             didFinishLaunchingWithOptions:launchOptions];
  return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]
  || [RNGoogleSignin application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

@end


Android

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

  • Platform that you're experiencing the issue on:

    • [] iOS

    • [] Android

    • [x] iOS but have not tested behavior on Android

    • [ ] Android but have not tested behavior on iOS

    • [ ] Both

  • If known, the version of the platform are you experiencing the issue on:

    • iOS 12.1 e.g. iOS 10 or Android API 28

  • Operating System:

    • [X] MacOS, version: 10.14.1

    • [ ] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • Xcode 10 e.g. Xcode 10, Android Studio 3.2

  • React Native version:

    • 0.56.0

  • React Native Firebase library version:

    • 5.1.0

  • Firebase module(s) you're using that has the issue:

    • [ ] N/A

    • [x] Authentication

    • [ ] Analytics

    • [x] Cloud Firestore

    • [ ] Cloud Messaging (FCM)

    • [x] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] Invites

    • [ ] Instance ID

    • [ ] Notifications

    • [x] Performance Monitoring

    • [ ] Realtime Database

    • [ ] Remote Config

    • [x] Storage

  • Are you using TypeScript?

    • [x] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [x] No

    • [ ] Yes, I've _not_ ejected

    • [ ] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: N/A




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Most helpful comment

Hey, @Baskerville42 thanks for taking the time to fill out this issue correctly. Appreciate it 馃挴

Since a user can sign into their Firebase Authentication account via a connected provider (Google/Facebook etc), the top-level provider id will (usually) be firebase.

But; as you can see in the output of currentUser there is a providerData property that provides information on the specific providers connected to that account. Looping over currentUser.providerData will give you the user.providerId that you're looking for.

If you need to determine the connected provider the user used to sign-in with for the current session on the device then I'd suggest storing this in AsyncStorage as part of your sign-in/signup flow on the device.

Hope this helps.

Thanks

All 2 comments

Hey, @Baskerville42 thanks for taking the time to fill out this issue correctly. Appreciate it 馃挴

Since a user can sign into their Firebase Authentication account via a connected provider (Google/Facebook etc), the top-level provider id will (usually) be firebase.

But; as you can see in the output of currentUser there is a providerData property that provides information on the specific providers connected to that account. Looping over currentUser.providerData will give you the user.providerId that you're looking for.

If you need to determine the connected provider the user used to sign-in with for the current session on the device then I'd suggest storing this in AsyncStorage as part of your sign-in/signup flow on the device.

Hope this helps.

Thanks

i looking for this so long, thank you so much!!!!

Was this page helpful?
0 / 5 - 0 ratings