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

问题描述 投票:1回答:1

this is my error第一个参数“verify 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);
            })
        }
    })

}

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

现在,您需要将验证码发送到登录状态。

我得到验证码并验证它然后错误即将来临。

LoginPage.html:32错误L

{
  code: "auth/argument-error", 
  message: "confirm failed: First argument "verificationCode" must be a valid string.", 
  ngDebugContext: DebugContext_, 
  ngErrorLogger: ƒ
}
angular typescript ionic-framework angularfire
1个回答
0
投票
<input type="number" name="code" [(ngModel)]="verificationCode"><br><br><br><br>

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

编辑:否则您可以在调用'confirm()'时将验证码解析为字符串

this.windowRef.confirmationResult
.confirm(this.verificationCode)  <-- parse to string
© www.soinside.com 2019 - 2024. All rights reserved.