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?
@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