Ok, so I've looked online and even read the documents provided by Google, however, I just cannot seem to figure out where I'm going wrong.
I wish to change the password of an account. This is my code right now:
var credential: AuthCredential! let user = Auth.auth().currentUser VStack { Text("Enter new password").font(.caption).foregroundColor(Color(SYSTEM_FONT_COLOUR)) PasswordTextField(password: $changeLoginDetailsViewModel.newPassword) Spacer() SignInButton(action: { self.user?.reauthenticate(with: self.credential) { (result, error) in if let error = error { print(error.localizedDescription) } } self.changeLoginDetailsViewModel.changePassword() }, label: "Update Password") } Every time I tap the "Update password" button, the application crashes. That's because credential is nil. So I did my research and found the method EmailAuthProvider(). So I added this line of code:
let email = EmailAuthProvider.credential(withEmail: (Auth.auth().currentUser?.email!)!, password: "thisIsNotTheRealPassword") For ethical reasons and best practice, I do not store user password within my database. So how can I even get/access the current user's password? Without storing it?
I guess I can get the user to enter their current password which would allow for reauthentication, but that is there a way in which I can do it whilst the view loads? So they're not required to hit the update password button twice? And for better UI experience. They user is already logged in, and are not required to login unless they sign out.