【问题标题】:Check username exist in database firebase angularfire2检查数据库firebase angularfire2中存在的用户名
【发布时间】:2017-10-28 23:31:13
【问题描述】:

注册和登录后,我要求用户创建一个配置文件。在那里我需要检查用户输入是否存在于数据库中,如果不创建配置文件。如您所见数据 [0] [4] = 数据库中的用户名。

使用 for 循环即时循环遍历所有配置文件用户名以查找用户名是否存在。现在它创建配置文件,即使用户名存在。

谢谢

https://image.prntscr.com/image/qDttSENCRqaOncLmpXNuhA.png

createProfile(){

    this.allData=this.db.list(`/profile/`).valueChanges();
    this.allData.take(1).subscribe(data => {
      let data = data.map(this.getObjectWithoutKnowingKey);
      console.log(data);
      console.log(data[0][4]);
       console.log(data.length);
console.log(this.username);


for(var i=0;0<data.length;i++){

if(data[i][4] === this.username){
  console.log("username already exist");
return;

}

}
});

//if username exist dont execute this code below.

this.fire.authState.take(1).subscribe(auth => {


this.db.object(`profile/${auth.uid}/`).set({
username: this.username,
msgnumber: 0,
asd: 0,
avatar: this.avatar


});
this.db.object(`profile/${auth.uid}/inventory/`).set({

test: 1


}).then(() => this.navCtrl.setRoot(TabsPage));



});






}

【问题讨论】:

    标签: javascript firebase ionic-framework firebase-realtime-database angularfire2


    【解决方案1】:

    通过代码,我可以看到您正在对数据进行迭代。所以这只会让你而不是尝试使用equalsTo firebase 方法。 Check it out.

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多