且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular 2+ Firebase 身份验证 - 设置登录状态持久性

更新时间:2023-12-03 10:51:40

您正在导入整个 firebase 模块.只导入auth.以下对我有用:

You're importing the entire firebase module. Only import auth. The following works for me:

// Don't import the whole module, only `auth`.
import { auth } from 'firebase/app';

constructor(private readonly afAuth: AngularFireAuth) { }

signIn() {
  this.afAuth.auth.setPersistence(auth.Auth.Persistence.LOCAL).then(() => {
    // Now sign-in using your chosen method.
    return this.afAuth.auth.signInAnonymously();
  }).catch((error) => {
    // Handle errors here.
    let errorCode = error.code;
    let errorMessage = error.message;
    console.error(errorCode, errorMessage);
  });
}