问题描述
我有一个离子应用程序,在其中我使用使用Recaptcha的Firebase电话身份验证.它在android上运行良好,但在ios上引发错误,提示recaptcha只能在http环境中运行.我想知道是否可以在不使用Recaptcha的情况下执行Firebase电话身份验证.
I have an ionic app where i use firebase phone authentication which uses recaptcha. It works fine on android but throws error on ios saying recaptcha can only be run in an http environment. I would like to know if there's a way to perform firebase phone auth without using recaptcha.
this.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container',{
'size': 'invisible'
});
let appVerifier = this.recaptchaVerifier;
this.appService.sendPhoneVerification(phoneNumber,appVerifier)
.then(confirmationResult => {
//do something
})
ios抛出错误"RECAPTCHA只能在HTTP/HTTPS环境中运行"
Ios throws error 'RECAPTCHA can only be run in HTTP/HTTPS environment'
推荐答案
这就是我解决我的问题'RECAPTCHA只能在HTTP/HTTPS环境中运行'的问题."
Well this is how I solved my issue "'RECAPTCHA can only be run in HTTP/HTTPS environment'".
- 安装Firebase插件:插件链接
- 将其添加到您的app.module.ts.
-
进行平台检查:检查其iOS.
- Install the Firebase Plugin :plugin link
- Add the it to your app.module.ts.
Make a platform check: to check if its iOS.
if (this.plt.is('ios')) { //ios code here } else { //android here }
if (this.plt.is('ios')) { //ios code here } else { //android here }
现在添加以下代码(iOS平台)以向用户发送验证码sms以验证电话号码.将插件注入构造函数.创建一个变量以分配诺言中的数据.电话号码应为国家代码+号码.例如'+19999999999'
Now add the following code (iOS platform) to send a verification code sms to the user to verify the phone number. Inject the plugin into the constructor. Create a variable to assign the data from the promise. Phone number should be country code + number. example '+19999999999'
public signInUser(phoneNum) { this.firebase.verifyPhoneNumber(phoneNum).then((vdata) => { this.refConfirm = vdata; //you can redirect the person to a verification page or show an alert to input verification code. });}
public signInUser(phoneNum) { this.firebase.verifyPhoneNumber(phoneNum).then((vdata) => { this.refConfirm = vdata; //you can redirect the person to a verification page or show an alert to input verification code. });}
现在创建令牌以使用Firebase使用凭据验证和登录用户.
Now create a token to verify and sign in user with credentials using firebase.
public verifyPhoneNumber(phoneNumber) { let tokenPhone = firebase.auth.PhoneAuthProvider.credential(this.refConfirm, phoneNumber); firebase.auth().signInWithCredential(tokenPhone).then((verifiedData) => { //whatever you want to do here or redirect the user to home page. });}
public verifyPhoneNumber(phoneNumber) { let tokenPhone = firebase.auth.PhoneAuthProvider.credential(this.refConfirm, phoneNumber); firebase.auth().signInWithCredential(tokenPhone).then((verifiedData) => { //whatever you want to do here or redirect the user to home page. });}
在Firebase&上生成您的GoogleService.plist添加到您的项目根目录
Generate your GoogleService.plist on Firebase & add to your project root directory
您必须添加反向的客户机ID,而不是普通的客户机ID.
You have to add reversed client id instead of normal one.
这就是我解决的方法.
这篇关于离子firebase phoneAuth在iOS上没有recaptcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!