使用firebase进行身份验证。 AuthWithOAuthPopup不是一个函数

时间:2017-10-13 05:21:11

标签: reactjs firebase firebase-authentication

我关注Wes Bos react for beginner教程(已更新),并且我坚持使用firebase进行身份验证。尝试使用github进行身份验证。

收到错误TypeError: __WEBPACK_IMPORTED_MODULE_3__base__.a.AuthWithOAuthPopup is not a function

我的代码与教程中的代码相同:

class Inventory extends React.Component {
  constructor() {
    super();
    this.renderInventory = this.renderInventory.bind(this);
    this.renderLogin = this.renderLogin.bind(this);
    this.authenticate = this.authenticate.bind(this);
    this.authHandler = this.authHandler.bind(this);
    this.handleChange = this.handleChange.bind(this);

    this.state = {
      uid: null,
      owner: null
    }
  }

  handleChange(e, key) {
    const fish = this.props.fishes[key];
    const updatedFish = {
      ...fish,
      [e.target.name]: e.target.value
    }
    this.props.updateFish(key, updatedFish);
  }

  authenticate(provider){
    console.log(`trying to login with ${provider}`);
    base.authWithOAuthPopup(provider, this.authHandler);
  }

  authHandler(err, authData) {
    console.log(authData);

  }
  renderLogin() {
    return (
      <div>
        <h1>Log In</h1>
        <button onClick={() => this.authenticate('github')}>Log In with Email</button>
      </div>
    )
  }

这是我的base.js文件的样子:

import Rebase from 're-base';
import firebase from 'firebase';

const config = {
   KEYS
};

const app = firebase.initializeApp(config)
const base = Rebase.createClass(app.database())

export default base;

1 个答案:

答案 0 :(得分:0)

在最新版本的Rebase中不推荐使用authWithOAuthPopup。您可以使用signInWithEmailAndPassword代替。见https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword