修改身份验证状态持久性错误

时间:2020-06-17 01:39:08

标签: javascript reactjs firebase firebase-authentication

我正在学习如何使用Firebase,现在正在尝试在React应用中修改Auth状态的持久性。我从firebase文档中获取了代码。

这是主要的js文件:

import Fire from "../../../firebase_config/Firebase"
var email = xxx@xxx.com
var password = xxx

Fire.auth().setPersistence(Fire.auth.Auth.Persistence.SESSION)
  .then(function() {
    // Existing and future Auth states are now persisted in the current
    // session only. Closing the window would clear any existing state even
    // if a user forgets to sign out.
    // ...
    // New sign-in will be persisted with session persistence.
    return Fire.auth().signInWithEmailAndPassword(email, password);
  })
  .catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
  });

这是firebase文件:

import firebase from "firebase"

const firebaseConfig = {
  apiKey: "xxx",
  authDomain: "xxx.com",
  databaseURL: "xxx.com",
  projectId: "xxx",
  storageBucket: "xxx.com",
  messagingSenderId: "xxx",
  appId: "xxx"
};
const Fire = firebase.initializeApp(firebaseConfig);
export default Fire

登录后,页面崩溃并输出以下错误: TypeError: _firebase_config_Firebase__WEBPACK_IMPORTED_MODULE_3__.default.auth.Auth is undefined

但是当我在不修改auth状态持久性的情况下使用此代码时,它就可以正常工作:

Fire.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

那我该如何解决这个错误?

0 个答案:

没有答案