【问题标题】:How to setup firebase auth local persistance?如何设置 Firebase 身份验证本地持久性?
【发布时间】:2019-04-05 10:00:36
【问题描述】:

我想实现一种方法来本地持久化我的 firebase 身份验证会话 使用以下方法:

firebase.auth.Auth.Persistence.LOCAL

这是我目前的实现

constructor(public af: AngularFireAuth, private router: Router, public afs: AngularFirestore ) { }

logIn(email, password) {

this.af.auth.setPersistence(firebase.app.auth.Auth.Persistence.LOCAL).then(() => {

  this.af.auth.signInWithEmailAndPassword(email, password).then((user) => {

    this.mailOutput.emit(email);

    this.router.navigate(['/pokemonlist']);
  }).catch(function (error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    if (errorCode === 'auth/wrong-password') {
      alert('Wrong password.');
    } else {
      alert(errorMessage);
    }
    console.log(error);
  });
});

}

我收到一个错误

'firebase' 指的是一个 UMD 全局,但当前文件是一个模块。考虑改为添加导入。

所以我把调用改为

this.af.auth.setPersistence(this.af.auth.Auth.Persistence.LOCAL).then(() => {

  this.af.auth.signInWithEmailAndPassword(email, password).then((user) => {  ....

现在我收到以下错误

类型“Auth”上不存在属性“Auth”

如何实现该功能?

【问题讨论】:

    标签: javascript angular firebase firebase-authentication


    【解决方案1】:

    通过导入修复它:

    import * as firebase from 'firebase';
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多