Expo,React Native Firebase:GoogleSignIn.initAsync():未定义不是对象

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

我按照docs的说明完成了所有这些操作>

1转到app.json,并确保定义了ios.bundleIdentifier和要使用的android.package。

2打开Firebase控制台并设置一个新项目,或使用现有的项目。

3使用您之前定义的Bundle ID和Android程序包创建本机iOS和Android应用。

4下载GoogleService-info.plist(iOS)和google-services.json(Android)。将它们移至您的Expo项目。

5在app.json中,将expo.ios.config.googleSignIn.reservedClientId设置为GoogleService-info.plist中的REVERSE_CLIENT_ID的值。

6同样在app.json中,将expo.android.googleServicesFile设置为google-services.json的相对路径。确保文件位于Expo项目中的某个位置。

我的登录屏幕:

import { GoogleSignIn } from 'expo-google-sign-in';

export default class SignIn extends React.Component {
  state = { user: null };


  componentDidMount() {
    this.initAsync();
  }

  initAsync = async () => {
    try {
      await GoogleSignIn.initAsync({ clientId: '{client id from the file here}' });
} catch ({ message }) {
  alert('GoogleSignIn.initAsync(): ' + message);
  console.log(message);
}

    this._syncUserWithStateAsync();
  };

  _syncUserWithStateAsync = async () => {
    const user = await GoogleSignIn.signInSilentlyAsync();
    this.setState({ user });
  };

signOutAsync = async () => {
    await GoogleSignIn.signOutAsync();
    this.setState({ user: null });
  };

  signInAsync = async () => {
    try {
      await GoogleSignIn.askForPlayServicesAsync();
      const { type, user } = await GoogleSignIn.signInAsync();
      if (type === 'success') {
        this._syncUserWithStateAsync();
      }
    } catch ({ message }) {
      alert('login: Error: ' + message);
    }
  };

  onPress = () => {
    if (this.state.user) {
       this.signOutAsync();
    } else {
      this.signInAsync();
    }
  };

  render() {
    return (
      <View style={styles.container}>            
        <View style={styles.buttonContainer}>
          <TouchableOpacity onPress={this.onPress}>
            <View style={styles.googleSignInButton}>
               <AntDesign name='google' size={32} style={styles.googleIcon} />
              <Text style={styles.buttonText}>Sign In using Google</Text>
             </View>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
};

我收到此错误

undefined is not an object (evaluating '_expoGoogleSignIn.GoogleSignIn.initAsync')

由于某种原因,我不知道,未定义返回GoogleSignIn对象。

帮助。

我按照文档中的说明进行了所有这些操作1转到您的app.json,并确保定义了ios.bundleIdentifier和要使用的android.package。 2打开Firebase控制台并进行设置...

firebase react-native firebase-authentication expo react-native-firebase
1个回答
0
投票

我有同样的问题。我在对我有用的expo forum上找到了该解决方案。更改

import GoogleSignIn from ‘expo-google-sign-in’;
© www.soinside.com 2019 - 2024. All rights reserved.