如何设置 firebase auth 本地持久性?

穆钦777

我想使用以下方法实现一种方法来在本地持久化我的 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'

我如何实现该功能?

穆钦777

通过导入修复它:

import * as firebase from 'firebase';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章