如何设置Firebase身份验证本地持久性?

时间:2019-04-05 10:00:37

标签: javascript angular firebase firebase-authentication

我想实现一种方法来本地保留我的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”

如何实现该功能?

1 个答案:

答案 0 :(得分:0)

通过导入修复了该问题:

import * as firebase from 'firebase';