Firebase和Gatsby构建不能很好地协同工作

时间:2019-11-05 00:12:43

标签: firebase gatsby

尝试登录时出现以下错误:

u.a.auth不是函数

错误在Login.js的这一行上:

app.auth().setPersistence(firebase.auth.Auth.Persistence.NONE);

在顶部,我有import app from "./base.js";

在base.js中,我有

import firebase from 'firebase/app';

var config = {
....
};

var app;
if(firebase.apps && firebase.apps.length > 0) {
  app = firebase.apps[0];
} else {
  app = firebase.initializeApp(config);
}
export default app;

那是我跑步之后

gatsby构建

盖茨比服务

1 个答案:

答案 0 :(得分:0)

您好,这是我的做法。工作正常:

import React from "react";
import firebase from "firebase";
...

const LoginForm = () => {

  const login = values => {
    firebase
      .auth()
      .signInWithEmailAndPassword(values.email, values.password)
      .then(() => { firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION);
        navigate("/app/profile");
      })
      .catch(error => {
        console.log("do something with the error:", error);
      });
  }

  return(
    <form onSubmit={login}>
    form details
    </form>
  );
};

export default LoginForm;