Firebase Auth - 最近登录多长时间 [英] Firebase Auth - How Long is Recent Login

查看:84
本文介绍了Firebase Auth - 最近登录多长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个个人资料标签,用户可以在其中按下编辑和编辑他们的个人资料。如果必须,我只想要他们的密码。所以想知道登录用户多少毫秒使它不是最近的登录,其中firebase会抛出错误auth / requires-recent-login编辑用户帐户时? new Date(Date.parse(firebase.auth()。currentUser.metadata.lastSignInTime))。getTime()会给我一个上次登录的近似值(以毫秒为单位) 2000毫秒)。我只是想知道我应该在什么时候要求用户重新进行身份验证?

I have a profile tab in which a user can press edit and edit their profile. I only want to require their password if I have to. So wanted to know how long is how many milliseconds of a user being signed in makes it not a recent login, in which firebase will throw the error "auth/requires-recent-login" when editing a users account? new Date(Date.parse(firebase.auth().currentUser.metadata.lastSignInTime)).getTime() Will give me an approximation of the last login (in milliseconds within 2000 milliseconds). I just want to know at what time should I ask the user to reauthenticate?

推荐答案

Firebase身份验证登录是永久性的对用户的身份验证没有特定的超时,因此您不应要求他们根据过期时间重新进行身份验证。

Firebase Authentication sign-ins are permanent There is no specific time-out on the authentication of a user, so you should not ask them to re-authenticate based on the expired time.

您唯一应该询问用户重新进行身份验证是指在需要最近身份验证的代码中执行操作,并且失败时出现 auth / requires-recent-login 错误代码。

The only you should ask the user to re-authenticate is when you perform an action in the code that requires recent authentication and it fails with a auth/requires-recent-login error code.

例如,这是 FirebaseUI在用户删除时检测到错误


 firebase.auth().currentUser.delete().catch(function(error) {
  if (error.code == 'auth/requires-recent-login') {
    // The user's credential is too old. She needs to sign in again.


这篇关于Firebase Auth - 最近登录多长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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