From e81bfdb2efdeffa465603ad091ddf90cf35b8251 Mon Sep 17 00:00:00 2001 From: pragatimodi <110490169+pragatimodi@users.noreply.github.com> Date: Mon, 6 May 2024 16:15:39 -0700 Subject: [PATCH] add password update option (#12635) --- .../Models/UserActions.swift | 1 + .../Utility/Extensions.swift | 1 + .../ViewControllers/UserViewController.swift | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/UserActions.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/UserActions.swift index da8e7721971..a2d87183c4a 100644 --- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/UserActions.swift +++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/UserActions.swift @@ -24,4 +24,5 @@ enum UserAction: String { case updateDisplayName = "Display Name" case updatePhoneNumber = "Phone Number" case refreshUserInfo = "Refresh User Info" + case updatePassword = "Update Password" } diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift index 4ce45df4020..e41a40df15a 100644 --- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift +++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift @@ -52,6 +52,7 @@ extension User: DataSourceProvidable { Item(title: UserAction.signOut.rawValue, textColor: .systemBlue), Item(title: UserAction.link.rawValue, textColor: .systemBlue, hasNestedContent: true), Item(title: UserAction.requestVerifyEmail.rawValue, textColor: .systemBlue), + Item(title: UserAction.updatePassword.rawValue, textColor: .systemBlue), Item(title: UserAction.tokenRefresh.rawValue, textColor: .systemBlue), Item(title: UserAction.delete.rawValue, textColor: .systemRed), ] diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/UserViewController.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/UserViewController.swift index 651c2e5f6ef..77ce4a9c792 100644 --- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/UserViewController.swift +++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/UserViewController.swift @@ -92,6 +92,9 @@ class UserViewController: UIViewController, DataSourceProviderDelegate { case .updateEmail: presentEditUserInfoController(for: actionName, to: updateUserEmail) + case .updatePassword: + presentEditUserInfoController(for: actionName, to: updatePassword) + case .updateDisplayName: presentEditUserInfoController(for: actionName, to: updateUserDisplayName) @@ -165,6 +168,19 @@ class UserViewController: UIViewController, DataSourceProviderDelegate { }) } + public func updatePassword(to newPassword: String) { + user?.updatePassword(to: newPassword, completion: { + error in + if let error = error { + print("Update password failed. \(error)", error) + return + } else { + print("Password updated!") + } + self.updateUI() + }) + } + public func updatePhotoURL(to newPhotoURL: String) { guard let newPhotoURL = URL(string: newPhotoURL) else { print("Could not create new photo URL!")