我正在尝试创建一个 React 应用程序,该应用程序使用“使用 Google 登录”按钮触发signInWithPopup(provider)
. 但是,每次我调用new firebaseApp.auth.GoogleAuthProvider()
我的控制台时都会返回一个错误。我只是想console.log()
的result
。
firebase_setup.js未捕获的类型错误:_firebase_setup2.default.auth.GoogleAuthProvider 不是构造函数
import * as firebase from 'firebase';
const firebaseConfig = {
apiKey: "AIzaSyAKlWtFZvbvuNy2qC68Xt5xzaTQVyy9l2o",
authDomain: "doordash-ff045.firebaseapp.com",
databaseURL: "https://doordash-ff045.firebaseio.com",
storageBucket: "doordash-ff045.appspot.com",
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
export default firebaseApp;
登录.js
import React, { Component } from 'react';
import { browserHistory } from 'react-router';
import firebaseApp from '../../../services/firebase_setup';
export default class Login extends Component {
componentDidMount() {
firebaseApp.auth().onAuthStateChanged(user => {
if (user) {
console.log(user);
browserHistory.push('/profile');
}
});
}
authenticate() {
var provider = new firebaseApp.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebaseApp.auth().signInWithPopup(provider)
.then(result => {
console.log(result);
})
}
render() {
return (
<div>
<h1>Login Page</h1>
<button onClick={this.authenticate.bind(this)}>
Login with Google
</button>
</div>
);
}
}
我将不胜感激对此问题的任何见解!我查阅了许多教程,但在尝试声明provider
变量时总是遇到相同的错误。