确认失败:第一个参数“验证码”必须为有效字符串

时间:2019-03-12 12:28:19

标签: angular typescript ionic-framework angularfire

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

在尝试验证代码时遇到此错误,请帮忙

login.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>

login.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);
            })
        }
    })

}

请告诉我如何解决此问题

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

我获得了VerificationCode并对其进行了验证,然后出现错误。

  

LoginPage.html:32错误L

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

2 个答案:

答案 0 :(得分:1)

您可以将类型从"number"更改为"tel",以便输入为字符串。

在代码更改中:

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

收件人:

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

答案 1 :(得分:0)

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

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

编辑: 否则,您可以在调用“ confirm()”时将VerificationCode解析为字符串

this.windowRef.confirmationResult
.confirm(this.verificationCode)  <-- parse to string