Firebase 身份验证 - 无法读取未定义的属性“_getIdTokenResponse”

问题描述 投票:0回答:1

由于 expo + React Native 和

react-native-google-signin
上出现
GoogleProvider
错误,我无法使用 Cannot read property '_getIdTokenResponse' of undefined 登录 Firebase。

import React, { useEffect, useState } from "react";
import { StyleSheet, View } from "react-native";

// Libs
import { GoogleAuthProvider, signInWithCredential } from "firebase/auth";
import {
  GoogleSignin,
  GoogleSigninButton,
} from "@react-native-google-signin/google-signin";

// App

export default function GoogleAuth() {
  const [isInProgress, setInProgress] = useState(false);

  useEffect(() => {
    GoogleSignin.configure({
      webClientId: 'xyz',
      offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
      forceCodeForRefreshToken: true, // [Android] related to `serverAuthCode`, read the docs link below *.
      profileImageSize: 480, // [iOS] The desired height (and width) of the profile image. Defaults to 120px
    });
  }, []);

  async function signIn() {
    try {
      setInProgress(true);
      await GoogleSignin.hasPlayServices();
      const { idToken } = await GoogleSignin.signIn();
      setInProgress(false);
      return signInWithCredential(GoogleAuthProvider.credential(idToken));
    } catch (error) {
      //
      setInProgress(false);
    }
  }

  return (
    <View style={styles.container}>
      <View style={styles.button}>
        <GoogleSigninButton
          size={GoogleSigninButton.Size.Icon}
          color={GoogleSigninButton.Color.Light}
          onPress={signIn}
          disabled={isInProgress}
        />
      </View>
    </View>
  );
}

"expo": "^49",
"react-native": "0.72.6",
"firebase": "^10.7.2",
javascript firebase react-native firebase-authentication expo
1个回答
0
投票

我不会混合使用

@react-native-google-signin/google-signin
firebase
。如果您希望利用 Google Sign In,请考虑使用
react-native-firebase
和 Firebase 身份验证的 GoogleAuthProvider。

您使用的配置不能协同工作,我不会感到惊讶。我猜测其中一个对象的

idToken
并不是为与另一个对象一起工作而设计的。

© www.soinside.com 2019 - 2024. All rights reserved.