angular - 确认失败 : First argument "verification Code" must be a valid string

标签 angular typescript ionic-framework angularfire

this is my error第一个参数“验证 ID”必须是有效字符串。

尝试验证代码时出现此错误,请帮忙

登录.html

<ion-content padding>
    <div>
        <ion-grid>
            <ion-label style="font-size: 20px;"> Please enter your phone number </ion-label>
            <ion-row justify-content-center>
                <div *ngIf="!windowRef.confirmationResult">
                    <div [hidden]="user" style="margin-top:35px;">
                            <ion-item>
                                <ion-input type="tel" maxlength="10" [(ngModel)]="contactNumber" placeholder="Enter Your Phone Number" clearInput required></ion-input>
                            </ion-item>
                    </div>

                    <button style="background-color: #3880ff; width: 135px;height: 40px;border-radius:25px;font-size: 20px;margin: 35px;color: white;" type="submit" (click)="checkeUserExist()">Submit</button>
                </div>

                <div id="recaptcha-container"></div>

                <div *ngIf="windowRef.confirmationResult">
                    <hr>
                    <label for="code">Enter your Verification Code Here</label>
                    <input type="number" name="code" [(ngModel)]="verificationCode"><br><br><br><br>

                    <button style="background-color: #3880ff; width: 70px;height: 28px;" full type="submit" (click)="verifyLoginCode()">Verify</button><br><br><br>
                    <ion-label style="font-size: 18px;"> Resend code Again ! </ion-label><br><br>
                    <button style="background-color: #3880ff; width: 100px;height: 32px;" full type="submit" (click)="sendLoginCode(contactNumber)">Resend code</button>
                </div>
            </ion-row>  
        </ion-grid>
    </div>
</ion-content>

登录.ts
ngOnInit() {
    this.windowRef = this.win.windowRef;
    this.windowRef.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
        //'type' : 'image',
        'size' : 'invisible',
        //'badge': 'inline' 
    });
    //this.windowRef.recaptchaVerifier.render();
}

sendLoginCode(contactNumber) {
    const appVerifier = this.windowRef.recaptchaVerifier;
    const num = "+91" + contactNumber;

    firebase.auth().signInWithPhoneNumber(num, appVerifier)
    .then(result => {
        this.windowRef.confirmationResult = result;
    })
    .catch( error => console.log(error) );
}

verifyLoginCode() {
    this.windowRef.confirmationResult
    .confirm(this.verificationCode)
    .then( result => {
        this.user = result.user;

        this.nav.navigateForward('addPatient');
    })
    .catch( error => console.log(error, "Incorrect code entered?"));
}

checkeUserExist() {
    var self = this;
    this.doctorUserCollection = this.db.collection('DoctorList').ref.where('contactNumber', '==', self.contactNumber)
    .get()
    .then(function(querySnapshot) {
        if(querySnapshot.empty) {
            self.nav.navigateForward(['/createAccount', { id: self.contactNumber }]);
        }
        else {
            querySnapshot.forEach(function(doc) {
                self.sendLoginCode(doc.data().contactNumber);
                localStorage.setItem('id', doc.data().uid);
            })
        }
    })

}

请告诉我如何解决这个问题

现在,您需要发送验证码来登录。

我得到了验证码并验证它然后错误来了。

LoginPage.html:32 ERROR L 

{
  code: "auth/argument-error", 
  message: "confirm failed: First argument "verificationCode" must be a valid string.", 
  ngDebugContext: DebugContext_, 
  ngErrorLogger: ƒ
}

最佳答案

<input type="number" name="code" [(ngModel)]="verificationCode"><br><br><br><br>

类型 输入的是“数字”。请删除 type 属性以使其工作。

编辑:
否则,您可以在调用 'confirm()' 时将 verifyCode 解析为字符串
this.windowRef.confirmationResult
.confirm(this.verificationCode)  <-- parse to string

关于angular - 确认失败 : First argument "verification Code" must be a valid string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55121477/

相关文章:

javascript - 通过在 Angular 2 应用程序中切换复选框来处理数组构建

typescript - commonjs 的单个 .js 和 .d 文件

javascript - 获取唯一键值计数作为对象

angularjs - 如何使用 ionic 框架在浏览器中打开 item.url

angular - 隐藏 Angular Material 2 表、特定标题及其列

node.js - undefined 不可迭代(无法读取属性 Symbol(Symbol.iterator))

angular - 工具提示问题,MatTooltip 在 Angular 中不起作用

javascript - Jasmine + TypeScript,找不到Spy类的withArgs()方法

html - 在 Cordova/Ionic 中放大特定的 div

javascript - Angular JS - Ionic - 从数组中删除