Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Ionic facebook登录如何区分新用户_Angular_Ionic Framework - Fatal编程技术网

Angular Ionic facebook登录如何区分新用户

Angular Ionic facebook登录如何区分新用户,angular,ionic-framework,Angular,Ionic Framework,我正在进行简单的ionic 4 facebook登录。并将数据保存在firebase中。但我面临的一个问题是,每当我点击firestore中的登录时,用户数据都会发生变化,这一点很明显。因为我不区分用户是新的还是现有的。有谁能告诉我如何检查firebase身份验证中的用户是否可用 这是我的密码 FacebookLogin(){ this.fb.login(['public_profile', 'user_friends', 'email']) .then((respon

我正在进行简单的ionic 4 facebook登录。并将数据保存在firebase中。但我面临的一个问题是,每当我点击firestore中的登录时,用户数据都会发生变化,这一点很明显。因为我不区分用户是新的还是现有的。有谁能告诉我如何检查firebase身份验证中的用户是否可用

这是我的密码

 FacebookLogin(){

     this.fb.login(['public_profile', 'user_friends', 'email'])
      .then((response: FacebookLoginResponse) => {
      this.onLoginSuccess(response);
      console.log('Logged into Facebook!', response);
      })

      .catch(e => console.log('Error logging into Facebook', e));


 }


   onLoginSuccess(res: FacebookLoginResponse) {
    const credential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
    this.fireAuth.auth.signInWithCredential(credential)
      .then((response) => {
      console.log(response);

        this.fb.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', []).then(profile => {
        this.userData = {email: profile['email'], first_name: profile['first_name'], picture: profile['picture_large']['data']['url'], username: profile['name']}
        console.log(this.userData);
        console.log(this.fireAuth.auth.currentUser.uid);

          let userData =  {
          email: this.userData.email,
          username: this.userData.username,
          photo: this.userData.picture,
          phone: '',
          point : '',
          uID: this.fireAuth.auth.currentUser.uid
        };

        this.angularFirestore.collection('AppUsers').doc(this.fireAuth.auth.currentUser.uid).set(userData); // Here is the data saving in firestore
        this.router.navigate(["/select"]);
      })

  });
  }

谁能告诉我如何检查用户是新的还是现有的?因此,如果用户存在,我不会将其保存在数据库中。

您的意思是firebase中的登录密钥再次作为新登录密钥插入,或者同一密钥上的其他用户的登录密钥内部数据正在更改?@MostafaHarb我正在firestore中保存数据。但每次用户登录时都会更改数据。我只想保存一次,如果用户再次使用相同的facebook登录,则不会更改数据。所以我正在寻找任何方法来检查用户是旧的还是新的。您正在将用户保存为其密钥,对吗?然后,您所需要做的就是进行查询,以在firestore中搜索此密钥或key.id。如果存在,则更新或不执行任何操作,否则插入用户。这就是你想要的吗?嗯,是的。。。。。。。。。