【发布时间】:2020-03-07 15:54:54
【问题描述】:
用户注册时使用电话验证。在使用该应用一段时间后,建议他们将一个(电子邮件和密码)链接到他们现有的帐户.
链接过程因错误(auth/requires-recent-login)而失败。我的代码如下。
// The following generates the error: [auth/requires-recent-login] This operation is sensitive and requires recent authentication. Log in again before retrying this request.
const emailCredential = firebase.auth.EmailAuthProvider.credential(state.email, state.password);
const newCredential = await firebase.auth().currentUser.linkWithCredential(emailCredential);
要修复此错误,我知道我需要在链接之前调用 reauthenticateWithCredential()。但是,我不想让用户再次登录(接收并输入验证码。)这可能吗?
我尝试将currentUser.getIdToken(true) 的结果传递给PhoneAuthProvider.credential() 我不确定这是否正确。无论如何,它生成了一个错误(如果没有验证证明、会话信息、临时证明或注册 ID,则无法创建 PhoneAuthCredential。)。
我的代码如下。
// The following works:
const accessToken = await firebase.auth().currentUser.getIdToken(true);
// The following works:
const currentCredential = firebase.auth.PhoneAuthProvider.credential(accessToken);
// The following generates the error: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.
const abc = await firebase.auth().currentUser.reauthenticateWithCredential(currentCredential);
// The following is never reached:
const emailCredential = firebase.auth.EmailAuthProvider.credential(state.email, state.password);
const newCredential = await firebase.auth().currentUser.linkWithCredential(emailCredential);
感谢您的努力和时间来帮助我......
【问题讨论】:
-
我遇到了同样的问题,但我有一个问题,我使用电话身份验证并在 firebase 控制台中手动设置了一个测试号码所以当我设置其他号码时,我无法接收任何验证码作为短信所以这对你有用吗?
-
@DevAS 我不确定我是否正确理解了您的问题。无论如何,我会尽力回答。我的理解是,您在 Android 模拟器上根本无法接收短信。如果您想尝试接收短信验证码,您需要在实际设备上部署您的应用。这能回答你的问题吗?
-
也许 ??我想说的是,我有一个登录屏幕,我使用我的实际号码登录,firebase 应该向我发送一条包含验证码的短信,对吗?但是我的手机收不到任何东西,“这是我的应用程序的调试版本,未发布”
-
@DevAS 看看这个:firebase.google.com/docs/auth/web/phone-auth
标签: node.js firebase react-native firebase-authentication react-native-firebase