Firebase 3.0会话持续时间 [英] Firebase 3.0 session persistance

查看:215
本文介绍了Firebase 3.0会话持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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


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

记住 - 字符串
如果没有指定 - 或者设为默认 - 会话是
,只要您在Login&您的应用程序面板的验证标签
。要将持久性限制在
当前窗口的生命周期中,请将其设置为sessionOnly。值为none将不会
持久化身份验证数据,并会在页面关闭时尽快结束身份验证

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


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



<另外,在新的控制台( https://console.firebase.google.com/ )我无法找到更改默认持久性的选项。

解决方案

也许值得一提的是,您需要等待auth状态来解决。根据文档:
$ b


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




  firebase.auth()。onAuthStateChanged(function(user){
if(user){
//用户已经登录。
} else {
//没有用户登录。
}
});

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


It seems impossible to use session persistence in firebase 3.0.

This was possible in the previous version: https://www.firebase.com/docs/web/guide/login/password.html

authWithPassword() takes an optional third parameter which is an object containing any of the following settings:

remember - String
If not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed.

In version 3.0 there is no mention of the optional 3rd parameter: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword

signInWithEmailAndPassword(email, password)
returns firebase.Promise containing non-null firebase.User

Also, in the new console (https://console.firebase.google.com/) I cannot find the option to change the default persistence.

解决方案

It may also be worth mentioning that you need to wait for the auth state to resolve. Per the docs:

The recommended way to get the current user is by setting an observer on the Auth object:

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

Link to the docs here: https://firebase.google.com/docs/auth/web/manage-users

这篇关于Firebase 3.0会话持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆