如果缺少名字或姓氏,则阻止Firebase社交用户身份验证

时间:2019-03-06 09:06:53

标签: angular firebase angularfire2

在使用社交凭据时,是否可以防止没有正确名字/姓氏的用户在Firebase上进行身份验证?我已经尝试了下面的方法,但实际上并没有用。用户部分登录并中断了应用程序。我想完全阻止他们并阻止他们使用该应用程序,并返回一条错误消息,告诉他们更正其帐户详细信息。

  facebookSignIn() {
    const provider = new auth.FacebookAuthProvider();
    return this.afAuth.auth.signInWithPopup(provider).then(async (result) => {
      const path = `/users/${result.user.uid}/`;
      const firstName = result.additionalUserInfo.profile['first_name'];
      const lastName = result.additionalUserInfo.profile['last_name'];
      const doc = await this.firebaseService.docExists(path);
      if (firstName && lastName) {
        if (!doc) {
          this.userService.processNewUser(result, firstName, lastName);
        }
        this.completeSignIn();
      } else {
        this.displayGenericError('Your Facebook account does not have a valid ' +
          'first or last name. Please update your profile before continuing.');
        localStorage.removeItem('user');
      }
    }).catch((error) => {
      this.displayGenericError(error);
    });
  }

  googleSignIn() {
    const provider = new auth.GoogleAuthProvider();
    return this.afAuth.auth.signInWithPopup(provider).then(async (result) => {
      const path = `/users/${result.user.uid}/`;
      const firstName = result.additionalUserInfo.profile['given_name'];
      const lastName = result.additionalUserInfo.profile['family_name'];
      if (firstName && lastName) {
        const doc = await this.firebaseService.docExists(path);
        if (!doc) {
          this.userService.processNewUser(result, firstName, lastName);
        }
        this.completeSignIn();
      } else {
        this.displayGenericError('Your Google account does not have a valid ' +
          'firstname or lastname. Please update your profile before continuing.');
        localStorage.removeItem('user');
      }
    }).catch((error) => {
      this.displayGenericError(error);
    });
  }

0 个答案:

没有答案