Vin*_*ngh 12 javascript firebase firebase-authentication
我第一次使用firebase phone auth,我看到验证码验证必须按照firebase官方文档继续进行.虽然它有一个很好的用途,但有时候当用户体验开始询问道路标志,桥梁等时,它会变得非常糟糕.有没有办法在获取用户号码后直接跳到验证码?根据文档,代码如下所述.谢谢.
var phoneNumber = getPhoneNumberFromUserInput();
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
}).catch(function (error) {
// Error; SMS not sent
// ...
});
var code = getCodeFromUserInput();
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
// ...
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
// ...
});
Run Code Online (Sandbox Code Playgroud)
小智 15
转到Firebase 控制台 --> 到您的项目 --> 项目概述设置 --> 项目设置 --> 应用程序检查 --> 概述(为 SafetyNet 注册您的应用程序)。
然后您的应用程序将停止重定向到网络进行验证码验证
小智 7
我在集成 iOS SDK 时遇到了同样的问题。
如果 google 跨语言具有相同的 firebase SDK 架构和类,则此解决方案可能适合您。
Auth.auth().settings?.isAppVerificationDisabledForTesting = true
Run Code Online (Sandbox Code Playgroud)
方法一:
firebase.auth().settings.appVerificationDisabledForTesting = true;
Run Code Online (Sandbox Code Playgroud)
Firebase 文档
https://firebase.google.com/docs/auth/web/phone-auth?authuser=0#web-v8_6
// Turn off phone auth app verification.
firebase.auth().settings.appVerificationDisabledForTesting = true;
var phoneNumber = "+16505554567";
var testVerificationCode = "123456";
// This will render a fake reCAPTCHA as appVerificationDisabledForTesting is true.
// This will resolve after rendering without app verification.
var appVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
// signInWithPhoneNumber will call appVerifier.verify() which will resolve with a fake
// reCAPTCHA response.
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// confirmationResult can resolve with the fictional testVerificationCode above.
return confirmationResult.confirm(testVerificationCode)
}).catch(function (error) {
// Error; SMS not sent
// ...
});
Run Code Online (Sandbox Code Playgroud)
方法2:
https://firebase.google.com/docs/auth/web/phone-auth#use-invisible-recaptcha
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
'size': 'invisible',
'callback': (response) => {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
}
});
Run Code Online (Sandbox Code Playgroud)
在身份验证设置中使用isAppVerificationDisabledForTesting = TRUE,如下所示:
Auth.auth().settings.isAppVerificationDisabledForTesting = TRUE
Run Code Online (Sandbox Code Playgroud)
更多详情请查看以下官方信息:
JavaScript - https://firebase.google.com/docs/reference/js/firebase.auth.AuthSettings
SDK 参考 - https://firebase.google.com/docs/auth/ios/phone-auth#integration-testing
| 归档时间: |
|
| 查看次数: |
4590 次 |
| 最近记录: |