在React Native中使用Firebase进行Google登录 [英] Google Sign In with Firebase in React Native
问题描述
我正在尝试使用Google登录,但抛出此错误:
I'm trying to login with Google but it throws me this error:
代码:此环境不支持身份验证/操作" 消息:运行此应用程序的环境不支持此操作."location.protocol"必须为http,https或chrome-extension,并且必须启用网络存储."
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."
这是代码:
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);
})
附加信息:
- "firebase":"^ 3.7.1"
- "react-native":"^ 0.42.0"
- 平台:Android
- "firebase": "^3.7.1"
- "react-native": "^0.42.0"
- platform: Android
Aditional Information:
有什么想法吗? 预先感谢!
any ideas? thanks in advance!
推荐答案
首先,我使用了 react-native-google-signin 以使用Google登录.请按照以下步骤进行配置
First I used react-native-google-signin to Sign In with Google. Follow these steps to configure it.
确保您正确签名 APK(调试或发布) ).
Make sure you correctly sign your APK (debug or release).
在app/build.gradle
中,将com.google.android.gms
从使用它的依赖项中排除,如下所示:
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
}
然后将您的Google令牌链接到Firebase:
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);
});
我正在使用Firebase 3.7.1
I'm using firebase 3.7.1
这是我的依赖项在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;
}
}
这篇关于在React Native中使用Firebase进行Google登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!