Firebase Google Auth在ReactJS

时间:2017-08-07 15:14:58

标签: reactjs firebase firebase-authentication google-authentication

我正在尝试在React + Firebase应用中实施Google登录。当我使用signInWithPopup()方法时,一切都很顺利。但是,当我使用signInWithRedirect() - 我的首选方法 - 身份验证仍然有效,但我在控制台中遇到了这些恼人的错误:

Uncaught TypeError: Cannot read property 'appendChild' of null
    at foundation-chrome-content.js:3

Error in event handler for extension.onRequest: TypeError: Cannot read property 'removeEventListener' of null
    at bindShortcuts (chrome-extension://nlipoenfbbikpbjkfpfillcgkoblgpmj/javascripts/content_script.js:1:9424)
    at chrome-extension://nlipoenfbbikpbjkfpfillcgkoblgpmj/javascripts/content_script.js:1:13864

这是我处理App.js身份验证的代码:

componentDidMount() {
  firebase.auth().onAuthStateChanged(user => this.setState({ user }));
  firebase.auth().getRedirectResult().then(result => {
    var user = result.user;
    this.setState({ user });
  }).catch(error => {
    if (error.code === 'auth/account-exists-with-different-credential') {
      alert('You have already signed up with a different auth provider for that email.');
    } else {
      console.error(error);
    }
  });
}

toggleSignIn = () => {
  if (this.state.user) {
    firebase.auth().signOut();
  } else {
    var provider = new firebase.auth.GoogleAuthProvider();
    firebase.auth().signInWithRedirect(provider);
  }
}

我很感激任何见解和帮助。

0 个答案:

没有答案