Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign In with Firebase in React Native

I'm trying to login with Google but it throws me this error:

code: "auth/operation-not-supported-in-this-environment" message: "This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled."

This is the code:

const provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.log(error);
  })

Aditional Information:

  • "firebase": "^3.7.1"
  • "react-native": "^0.42.0"
  • platform: Android

any ideas? thanks in advance!

like image 939
AlejandroJS Avatar asked Mar 14 '17 17:03

AlejandroJS


People also ask

How do you do Google sign-in in react native?

For Android First, we need to link the native module. In RN >= 0.60 you should not need to do anything thanks to auto-linking. In RN < 0.60 run react-native link react-native-google-signin .

Can I use Firebase with react native?

To get started, you must first setup a Firebase project and install the "app" module. React Native Firebase is the officially recommended collection of packages that brings React Native support for all Firebase services on both Android and iOS apps.


1 Answers

First I used react-native-google-signin to Sign In with Google. Follow these steps to configure it.

Make sure you correctly sign your APK (debug or release).

In app/build.gradle exclude com.google.android.gms from the dependencies that use it like so:

compile(project(":react-native-google-signin")){
    exclude group: "com.google.android.gms" // very important
}

Then link you Google token with Firebase:

const provider = firebase.auth.GoogleAuthProvider;
const credential = provider.credential(token);
firebase.auth().signInWithCredential(credential)
  .then((data) => {
    console.log('SUCCESS', data);
  })
  .catch((error) => {
    console.log('ERROR', error);
  });

I'm using firebase 3.7.1

This is how my dependencies look in app/build.gradle

dependencies {
    compile project(':react-native-facebook-login')
    compile (project(':react-native-fcm')){
        exclude group: "com.google.firebase"
    }
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"
    compile(project(":react-native-google-signin")){
        exclude group: "com.google.android.gms" // very important
    }
    compile ('com.google.firebase:firebase-core:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:10.0.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-auth:10.0.1') {
        force = true;
    }
}
like image 195
AlejandroJS Avatar answered Oct 27 '22 10:10

AlejandroJS