简体   繁体   English

Firebase-Web-验证帐户而没有可用的电子邮件

[英]Firebase - Web - verify account without available email

In my application I added some other providers like twitter or facebook for the sign-in process. 在我的应用程序中,我添加了一些其他提供商(例如twitter或facebook)用于登录过程。 With the twitter provider in one case, it does not fetch the email-address. 在一种情况下使用Twitter提供程序时,它不会获取电子邮件地址。 I suspect, because twitter does not know the email of the user (possibly only logged in with a phone-number). 我怀疑,因为Twitter不知道用户的电子邮件(可能仅使用电话号码登录)。 Now how can I verify the user if there is no email to use <firebase.User>user.sendEmailVerification() ? 现在,如何验证用户是否没有可使用<firebase.User>user.sendEmailVerification()电子邮件?

I can offer some code for the sign-in process of my app using Angular. 我可以使用Angular为我的应用程序登录过程提供一些代码。

Service 服务

  public async loginWithDifferentProvider(provider: 'Google' | 'Facebook' | 'Twitter'): Promise<void | string | boolean> {
    let auth;
    switch (provider) {
      case 'Google':
        auth = new firebase.auth.GoogleAuthProvider();
        break;
      case 'Facebook':
        auth = new firebase.auth.FacebookAuthProvider();
        break;
      case 'Twitter':
        auth = new firebase.auth.TwitterAuthProvider();
        break;
    }

    try {
      await this.oAuthLogin(auth);
      return this.router.navigate(['/stories']);
    } catch (e) {
      this.notify.danger(e.message);
    }
  }

  private async oAuthLogin(provider) {
    const loginMetaData: UserCredential = await this.auth.firebaseAuthInstance.signInWithPopup(provider);
    const user: firebase.User = loginMetaData.user;
    let photoUrl: string;

    switch (loginMetaData.credential.providerId) {
      case 'twitter.com':
        photoUrl = loginMetaData.user.photoURL.replace('_normal', '');
        break;
      case 'facebook.com':
        const id = loginMetaData.additionalUserInfo.profile['id'];
        photoUrl = `https://graph.facebook.com/${id}/picture?type=large`;
        break;
    }

    return this.userService.createUserFromOtherProvider(user, photoUrl); // creates firestore doc. of the user
  }

The sendEmailVerification method is specifically made to verify the user's email address. sendEmailVerification方法专门用于验证用户的电子邮件地址。 If there is no email address in the user's profile, it's meaningless to call the method. 如果用户个人资料中没有电子邮件地址,则调用该方法毫无意义。

You could detect that their profile doesn't have an email address, and then ask the user for their email address. 您可以检测到他们的个人资料没有电子邮件地址,然后向用户询问他们的电子邮件地址。 You can then set the email address in their Firebase Authentication profile and call sendEmailVerification after that to verify it. 然后,您可以在其Firebase身份验证配置文件中设置电子邮件地址,然后再调用sendEmailVerification进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM