首页 文章

Firebase 3.0会话持久性

提问于
浏览
6

在firebase 3.0中使用会话持久性似乎是不可能的 .

这在以前的版本中是可能的:https://www.firebase.com/docs/web/guide/login/password.html

authWithPassword()接受一个可选的第三个参数,该参数是包含以下任何设置的对象:remember - String如果未指定 - 或设置为default,只要您在Login&Auth选项卡中配置了会话,会话就会保持不变App仪表板 . 要将持久性限制为当前窗口的生命周期,请将其设置为sessionOnly . 值none将不会保留身份验证数据,并且会在页面关闭后立即结束身份验证 .

在3.0版中,没有提到可选的第3个参数:https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword

signInWithEmailAndPassword(email,password)返回包含非null firebase的firebase.Promise .

此外,在新的控制台(https://console.firebase.google.com/)中,我找不到更改默认持久性的选项 .

3 回答

  • 5

    值得一提的是,您需要等待auth状态才能解决 . 根据文档:

    获取当前用户的推荐方法是在Auth对象上设置观察者:

    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
      } else {
        // No user is signed in.
      }
    });
    

    链接到这里的文档:https://firebase.google.com/docs/auth/web/manage-users

  • 2

    在3.0中,用户当前始终保持不变,直到调用signOut()(或用户清除本地存储) .

  • 3

    Firebase Auth JS SDK现在支持sessionOnly持久性 . 有关详细信息,请查看https://firebase.google.com/support/release-notes/js#4.2.0https://firebase.google.com/docs/auth/web/auth-state-persistence

    您现在可以在登录之前或之后指定或切换验证状态持久性 . 对于您的情况,您可以按如下方式指定仅会话持久性: firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)

相关问题