0

通过这段代码。

googleAuthenticate = (token) => {
const provider = firebase.auth.GoogleAuthProvider();
const credential = provider.credential(token)
return firebase.auth().signInWithCredential(credential) }


gglogin = async () => {
const LogInResult = await Google.logInAsync({
      androidClientId: '<my-androidClientId>',
      iosClientId: '<my-IOSClientId>',
      scopes: ['profile', 'email']
});

if(LogInResult.type === 'success'){
  Alert.alert(
        'Logged in!',
        `Hi ${user.name}!`,
      );
  this.googleAuthenticate(LogInResult.accessToken)
}

}

它可以获得用户名警报,但无法通过收到此错误将令牌发送到 Firebase。

Possible Unhandled Promise Rejection (id: 0):
  TypeError: this.addScope is not a function. (In 
 'this.addScope("profile")', 'this.addScope' is undefined)`

请问有什么问题

4

2 回答 2

0

您必须将您的范围添加到提供程序,如下所示:

var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);

请再次检查此文档: https ://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider

您需要更改您的代码如下:

googleAuthenticate = (token) => {
const provider = firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
const credential = provider.credential(token)
return firebase.auth().signInWithCredential(credential) }
于 2017-06-17T16:22:06.080 回答
0

我注意到 2 个问题,凭证是一个静态方法,第一个参数是一个 id 令牌,第二个参数是一个访问令牌(您似乎正在传递一个访问令牌):

const credential = firebase.auth.GoogleAuthProvider.credential(null, token);
return firebase.auth().signInWithCredential(credential);
于 2017-06-19T06:26:42.307 回答