firebase.auth()。setPersistence错误的“持久性”未定义

时间:2018-12-21 15:41:11

标签: javascript reactjs firebase

我正在使用Firebase auth处理表单中的用户身份验证,但出现此错误

  

未定义的“持久性”错误

添加firebase.auth().setPersistence时。

onSubmit = event => {
  const { firebase } = this.props;
  const { email, password, remember } = this.state;
  firebase
    .doSignInWithEmailAndPassword(email, password, remember)
    .then(authUser => {
      firebase.doEmailUpdateUser(authUser);
    })
    .then(() => {
      this.setState({ error: null });
      navigate(ROUTES.INDEX);
    })
    .catch(error => {
      this.setState({
        error,
        errorOpen: true
      });
    });

  event.preventDefault();
};

firebase.doSignInWithEmailAndPassword(email, password, remember)

doSignInWithEmailAndPassword = (email, password, remember) => {
  this.auth
    .setPersistence(
      `${
        remember
          ? this.auth.Auth.Persistence.LOCAL
          : this.auth.Auth.Persistence.SESSION
      }`
    )
    .then(() => this.auth.signInWithEmailAndPassword(email, password));
};

以供参考this.auth = app.auth();

我在这里错过了什么吗?我做错了什么?

1 个答案:

答案 0 :(得分:1)

好像您正在尝试从错误的对象中获取Auth.Persistence。您说this.auth = app.auth(),所以我假设app是从Firebase像import app from 'firebase'导入的。如果不正确,请告诉我如何导入。

如果我的假设正确,那么您将需要访问app.auth.Auth.Persistence.LOCAL之类的属性。您当前的版本更像app.auth().Auth.Persistence.LOCAL