Ionic - 电子邮件地址格式错误

时间:2018-03-29 05:50:57

标签: angular firebase ionic-framework firebase-authentication

我正在开发一个离子项目,我使用firebase作为后端,我正在建立一个注册和登录表单。每当我注册代码时运行良好。当我尝试使用“signInWithEmailAndPassword”检索它时,我收到以下错误。电子邮件地址格式错误的Firebase。首次创建帐户时成功登录。但登录后出现相同的电子邮件和密码错误。

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


@IonicPage()
@Component({
 selector: 'page-signin',
 templateUrl: 'signin.html',
})

export class SigninPage {

 @ViewChild('email') email;
 @ViewChild('password') password;

constructor(public alertCon: AlertController, public afAuth: AngularFireAuth, public navCtrl: NavController, public navParams: NavParams) {
}

    ionViewDidLoad() {
      console.log('ionViewDidLoad SigninPage');
    }

   alert(title, message){
    this.alertCon.create({
    title: title,
    subTitle: message,
    buttons: ['OK']
  }).present();
  }

  userSignin(){
  this.afAuth.auth.signInWithEmailAndPassword(this.email.value, this.password.value)
 .then(data=>{
  console.log('loged in');
  this.navCtrl.setRoot(HomePage);
  this.alert('WELCOME', 'You are loged in');
})
 .catch(error=>{
  console.log('Error', error)
  this.alert('ERROR!', 'password or Email is wrong');
  });
 }

}

1 个答案:

答案 0 :(得分:0)

我建议您在单独的文件夹中创建用户模型。 使用以下方式定义用户模型:

导出界面用户{
    id?:string     电子邮件:string;     密码:字符串;

}

然后在LogIN ts文件中创建用户模型的新obj,前提是您已在登录ts文件中导入模型。

user = {} as User;

您可以登录功能
loginUser(user:User){this.logauth.auth.signInWithEmailAndPassword(user.email,user.password);

}

如果数据在对象而不是属性中传递,则Angular的效果会更好。 因此,此方面的用户模型将保留登录html页面中的用户数据并传递给登录TS文件中的对象。希望这可以帮助。