Firebase 3.0会话持久性

WSa*_*Sas 7 session persistence firebase firebase-authentication

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

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

authWithPassword()接受一个可选的第三个参数,该参数是包含以下任何设置的对象:

remember - String
如果未指定 - 或设置为default,只要您在App Dashboard的Login&Auth选项卡中配置,会话就会保持不变.要将持久性限制为当前窗口的生命周期,请将其设置为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/)中,我找不到更改默认持久性的选项.

bra*_*can 5

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

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

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});
Run Code Online (Sandbox Code Playgroud)

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


小智 3

在 3.0 中,用户当前始终保留到调用 signOut() 为止(或用户清除本地存储)。