【问题标题】:TypeError: Cannot read property 'configure' of undefined in react-nativeTypeError:无法读取 react-native 中未定义的属性“配置”
【发布时间】:2018-12-20 09:08:22
【问题描述】:

我在 Ios 中使用 react-native 在 android 中执行 googleSignIn 时遇到了这个问题,它完全可以正常工作,但在 ios 中却不是。我也用 cocoapods 尝试过,但它不起作用。我想这是链接的问题,但我按照 googlesignIn ios 文档来实现它,并尝试使用 unlink 和链接 google signIn 但它不起作用。请有人帮帮我。

以下是 googleSignIn 的代码。

 componentDidMount() {
            this.unsubscriber = firebase.auth().onAuthStateChanged((changedUser) => {
                // console.log(`changed User : ${JSON.stringify(changedUser.toJSON())}`);
                this.setState({ user: changedUser });
            });
            GoogleSignin.configure({
                iosClientId: '180169766571-2cfig8ri85cplmmdpnk2mcv0vb042055.apps.googleusercontent.com', // only for iOS
            })
            .then(() => {
                // you can now call currentUserAsync()
            });
        }

    onLoginGoogle = () => {
            GoogleSignin
              .signIn()
              .then((data)=> {
                  // create a new firebase credential with the token
                  const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
                  // login with credential
                  return firebase.auth().signInWithCredential(credential);
              })
              .then((currentUser)=>{
                  console.log(`Google Login with user : ${JSON.stringify(currentUser.toJSON())}`);
              })
              .catch((error) => {
                  console.log(`Login fail with error ${error}`);
              });
        }

【问题讨论】:

    标签: react-native firebase-authentication google-signin react-native-ios


    【解决方案1】:

    像这样单独使用配置

    componentDidMount(){
    this.GoogleSignIn
    }
    
    GoogleSignIn = async () => {
        await GoogleSignin.configure({
            iosClientId:'key',
            offlineAccess: false,
        });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-17
      • 2020-11-05
      • 2020-04-17
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多