简体   繁体   English

如何在flutter中验证firebase auth中的电子邮件?

[英]How to verify an email in firebase auth in flutter?

I've created a login screen using firebase & flutter and Everything is going okay but I want the user to sign in with a real email (verified) not any email.我已经使用 firebase 和 flutter 创建了一个登录屏幕,一切正常,但我希望用户使用真实的电子邮件(已验证)而不是任何电子邮件登录。

if the user clicks signs in button with an email like that : shsuhsafk@uisl.com, it will accept this email.如果用户单击带有类似电子邮件的登录按钮:shsuhsafk@uisl.com,它将接受该电子邮件。

how to verify that the email isn't fake and actually belong to a real address.如何验证电子邮件不是伪造的并且实际上属于真实地址。

In order to really verify the users e-mail address you need to send a verification mail which requires action from the user.为了真正验证用户的电子邮件地址,您需要发送一封验证邮件,这需要用户采取行动。

Only checking if the address exists is insufficient as the e-mail address could belong to anyone.仅检查地址是否存在是不够的,因为电子邮件地址可能属于任何人。

You can set up a mail template in your Firebase Console and use the following code to send the verification mail.您可以在 Firebase 控制台中设置邮件模板并使用以下代码发送验证邮件。

FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
     try {
        await user.sendEmailVerification();
        return user.uid;
     } catch (e) {
        print("An error occured while trying to send email        verification");
        print(e.message);
     }
   }
String email = "user@example.com";
try {
  String link = FirebaseAuth.getInstance().generateSignInWithEmailLink(
      email, actionCodeSettings);
  // Construct email verification template, embed the link and send
  // using custom SMTP server.
  sendCustomPasswordResetEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
  System.out.println("Error generating email link: " + e.getMessage());
}

Please refer Below link for more info: https://firebase.google.com/docs/auth/admin/email-action-links请参阅以下链接了解更多信息: https : //firebase.google.com/docs/auth/admin/email-action-links

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

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