Ionic / Angular / FIrebase:类型“ UserCredential”上不存在属性“ emailVerified”

时间:2018-10-19 10:37:45

标签: angular firebase ionic-framework ionic3 firebase-authentication

我遇到错误,我试图在Ionic 3 Framework中使用Angular和Firebase身份验证创建登录名。问题是我不知道如何解决该错误。

错误消息

Typescript Error

Property 'emailVerified' does not exist on type 'UserCredential'.

src/pages/login/login.ts

代码Login.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, AlertController } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';

@IonicPage()
@Component({
    selector: 'page-login',
    templateUrl: 'login.html',
})
export class LoginPage {
    user: any = {}

    constructor(private navCtrl: NavController, private afAuth: AngularFireAuth, private alertCtrl: AlertController) {
    }

    login() {
        this.afAuth.auth.signInWithEmailAndPassword(this.user.email, this.user.password).then(data => {
            if (!data.emailVerified) {
                let alert = this.alertCtrl.create({
                    title: 'Failed',
                    message: 'Email has not been verified',
                    buttons: ['OK']
                })
                alert.present()
            } else {
                this.navCtrl.setRoot('HomePage')
            }
        }).catch(err => {
            let alert = this.alertCtrl.create({
                title: 'Failed',
                message: err.message,
                buttons: ['OK']
            })
            alert.present()
        })
    }

    toRegister() {
        this.navCtrl.push('RegisterPage')
    }

    toResetPassword() {
        this.navCtrl.push('ResetPasswordPage')
    }

}

1 个答案:

答案 0 :(得分:0)

应为data.user.emailVerifiedsignInWithEmailAndPassword返回一个UserCredential对象。