step-up-labs / firebase-authentication-dotnet

C# library for Firebase Authentication
MIT License
376 stars 129 forks source link

Email verification #195

Open Mustimain opened 1 year ago

Mustimain commented 1 year ago

How can I send an email for email verification? Please help me

domsse commented 1 year ago

Hey @Mustimain, I recently asked myself the same question when I started a new project. Have you already found a solution to this or is the question still open?

Mustimain commented 1 year ago

still open unfortunately i couldn't find a solution

domsse commented 1 year ago

@Mustimain i have now sat down to the problem and complete the email verification via a small detour. I use the Nuget: "NuGet\Install-Package FirebaseAdmin -Version 2.3.0" in my Project to create an Email Verification Link.

I created a FirebaseAdmin.FirebaseApp after the registration and created the link based on the email from the user. Afterwards I deleted the FirebaseApp instance. (Could certainly be kept for further functions from the FirebaseAdmin SDK).

public async Task RegistrationUser(string email, string password, string username)
{
     UserCredential = await authViewModel.RegisterUserWithEmail(email, password, username);
     User = UserCredential.User;

     FirebaseApp.Create(new AppOptions()
     {
          Credential = GoogleCredential.FromFile(filePath)
     });

     var link = await FirebaseAuth.DefaultInstance.GenerateEmailVerificationLinkAsync(email);

     FirebaseApp.DefaultInstance.Delete();

     await SendEmailVerificationAsync(link, email, username);
}

Afterwards I created a SmtpClient and sent an email to the user. This worked fine for me. (So you can also design the email according to your own wishes, which was also my wish).

Let me know if I could help you a little bit with my detour. (Sorry for my funny english, english is not my main language. ^^)

Mustimain commented 1 year ago

@domsse thank you for your help solved my problem

koddek commented 1 year ago

@domsse @Mustimain were you working on a .NET MAUI app? I can't get SmtpClient to work on .NET MAUI.

domsse commented 1 year ago

Hi @koddek I have been working with a .NET MAUI application. I used normal SmtpClient (using System.Net.Mail) with own credential. What did you do? Do you have a sample code for me where it doesn't work?

koddek commented 1 year ago

Hi @domsse, thanks for your reply

What did you do? Do you have a sample code for me where it doesn't work?

I created a clean .NET MAUI app. Both the XAML and Blazor versions.

This code works on Blazor Server, but not on Webassembly.