From 954ffcb21146052f6b485c2834c5007c9e039b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Wed, 28 Aug 2024 09:44:29 +0200 Subject: [PATCH 1/2] Add ChangeEmailAsync function This new function allows the user's email address to be changed. --- src/Auth/User.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Auth/User.cs b/src/Auth/User.cs index 03021d9..6dccbc9 100644 --- a/src/Auth/User.cs +++ b/src/Auth/User.cs @@ -91,6 +91,31 @@ public async Task DeleteAsync() this.config.UserManager.DeleteExistingUser(this.Uid); } + /// + /// Change user's Email address. + /// + /// The new Email address. + public async Task ChangeEmailAsync(string email) + { + var token = await this.GetIdTokenAsync().ConfigureAwait(false); + var result = await this.updateAccount.ExecuteAsync(new UpdateAccountRequest + { + IdToken = token, + Email = email, + ReturnSecureToken = true + }).ConfigureAwait(false); + + this.Credential = new FirebaseCredential + { + ExpiresIn = result.ExpiresIn, + IdToken = result.IdToken, + ProviderType = this.Credential.ProviderType, + RefreshToken = result.RefreshToken + }; + + this.config.UserManager.UpdateExistingUser(this); + } + /// /// Change user's password. /// From f2dc1076847091f80449ab4a2e7c8091f4a60f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Wed, 28 Aug 2024 09:56:29 +0200 Subject: [PATCH 2/2] Add Email field to UpdateAccountRequest --- src/Auth/Requests/UpdateAccount.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Auth/Requests/UpdateAccount.cs b/src/Auth/Requests/UpdateAccount.cs index ea3e775..613f242 100644 --- a/src/Auth/Requests/UpdateAccount.cs +++ b/src/Auth/Requests/UpdateAccount.cs @@ -2,6 +2,8 @@ { public class UpdateAccountRequest : IdTokenRequest { + public string Email { get; set; } + public string Password { get; set; } public bool ReturnSecureToken { get; set; }