React-native-firebase: Authentication with federated providers

Created on 6 Apr 2017  路  8Comments  路  Source: invertase/react-native-firebase

The Authentication doc states that:

RNFirebase handles authentication for us out of the box, both with email/password-based authentication and through oauth providers (with a separate library to handle oauth providers).

I couldn't find, however, what separate library you recommend (or maybe include). Could you please clarify?

Docs Question

All 8 comments

@guigrpa I couldn't specifically recommend a library as there are plenty out there, but I can give you an example using the official react native facebook sdk:

import { AccessToken, LoginManager } from 'react-native-fbsdk';

// ... somewhere in your login screen component
LoginManager
  .logInWithReadPermissions(['public_profile', 'email'])
  .then((result) => {
    if (result.isCancelled) {
      return Promise.resolve('cancelled');
    }
    console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`);
    // get the access token
    const data = AccessToken.getCurrentAccessToken();

    // create a new firebase credential with the token
    const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);

    // login with credential
    return firebase.auth().signInWithCredential(credential);
  })
  .then((currentUser) => {
    if (currentUser === 'cancelled') {
      console.log('Login cancelled');
    } else {
      // now signed in
      console.warn(JSON.stringify(currentUser.toJSON()));
    }
  })
  .catch((error) => {
    console.log(`Login fail with error: ${error}`);
  });

Hope this helps?

I've also added this example to the auth docs 馃憤

Thanks for the fast response! Any suggestion for Google sign-in?

Give react-native-oauth a go, does most providers as far as I know. It'd then just be GoogleAuthProvider instead FacebookAuthProvider

@Salakar Just a follow-up question: is react-native-firebase not using the native SDK? If it does, why does it need another lib for social authentication? As far as I understand, the native SDK for Android and iOS has federated auth.

@Salakar i am implementing the login via facebook, but in my call to

firebase.auth.FacebookAuthProvider.credential(accessToken)

it says that it is not a valid function so i have include the

compile "com.google.firebase:firebase-core:11.0.0"
compile "com.google.firebase:firebase-auth:11.0.0"

in my app's build.gradle file along with adding it to mainApplication.java but while building i am getting an error
cannot find symbol

import io.invertase.firebase.auth.RNFirebaseAuthPackage;

can you plz help me out.

thanks, figured it out by myself, thanks.

@coding-bird Could you please explain how you figured it out? Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

escobar5 picture escobar5  路  3Comments

n-scope picture n-scope  路  3Comments

csumrell picture csumrell  路  3Comments

joecaraccio picture joecaraccio  路  3Comments

Damnum picture Damnum  路  3Comments