【问题标题】:Ionic - The Email Address is Badly FormattedIonic - 电子邮件地址格式错误
【发布时间】:2018-09-07 23:44:14
【问题描述】:

我正在开发一个 ionic 项目,我使用 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');
  });
 }

}

【问题讨论】:

  • 您用来登录用户的代码在哪里?
  • 对不起!!我的错误..我编辑了帖子。

标签: angular firebase ionic-framework firebase-authentication


【解决方案1】:

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

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

}

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

user= {} 作为用户;

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

}

如果数据是在对象而不是属性中传递的,Angular 会更好地工作。 所以这方面的User Model会持有来自login html页面的用户数据,并传递给Login TS File中的对象。希望这可以帮助。

【讨论】:

  • 您能更好地解释一下自己并为您的代码示例添加一些格式吗?
  • i 建议您在模型文件夹中创建一个用户模型。导出接口用户{ id?:字符串;用户名:字符串;电子邮件:字符串;密码:字符串;角色:角色; }
猜你喜欢
  • 2018-09-09
  • 1970-01-01
  • 2017-02-01
  • 2018-02-18
  • 2018-09-24
  • 2021-01-11
  • 2021-01-03
  • 2021-03-25
  • 2020-08-01
相关资源
最近更新 更多