Firebase身份验证:手动检测当前用户最近是否已通过身份验证 [英] Firebase Auth: Manually detect if the current user has recently authenticated

查看:72
本文介绍了Firebase身份验证:手动检测当前用户最近是否已通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,如果用户在X之前登录,Firebase将要求他/她通过 reauthenticateWithCredential 重新进行身份验证,以完成操作.

By default, if the user signed in X time ago, Firebase will require him/her to reauthenticate via reauthenticateWithCredential in order to complete the action.

如果用户在进行下一步操作之前已经具备重新认证的资格,是否可以查询Firebase API?

Is there a way to query the Firebase API if the user already qualifies for reauthentication before proceeding with next action?

推荐答案

对于某些敏感操作,Firebase身份验证API要求用户最近(重新)对其凭据进行身份验证.

For certain sensitive operations the Firebase Authentication API require that the user has recently (re)authenticated with their credentials.

当前无法检测到特定呼叫是否需要这种重新认证,也没有关于Firebase要求重新认证之前的时间间隔的文档.

There is currently no way to detect whether a specific call will require such re-authentication, nor documentation on how long the interval is before Firebase requires re-authentication.

实现此目的的正确方法是执行操作并捕获错误.如果 error.code auth/requires-recent-login 要求用户重新进行身份验证,使用新的凭据调用 reauthenticateWithCredential ,然后重试该操作.

The proper way to implement this, is to perform the operation, and catch errors. If the error.code is auth/requires-recent-login ask the user to re-authenticate, call reauthenticateWithCredential with the fresh credentials, and then retry the operation.

这篇关于Firebase身份验证:手动检测当前用户最近是否已通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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