'When the user updates the e-mail address with the link

I'm developing an app where people can meet and chat. When a user wants to update their e-mail address, I get help from the following firebase function.

        if let user = Auth.auth().currentUser {
        user.sendEmailVerification(beforeUpdatingEmail: mail, completion: {error in
            if let error = error {
                print(error)
                self.presenter?.onStateChange(
                    state: .CHANGE_MAIL_FAIL(message: "An error occurred. Try again later.".localized())
                )
                return
            }
            self.presenter?.onStateChange(state: .SUCCESS_MAIL_CHANGE) // sended verification link
        })
    }

This function sends a link to the user's new email address.If the user confirms with this link, the e-mail address is updated.

When the user updates their e-mail address, I need to make changes to the firestore database.

enter image description here

How can I update the database at the same time the user's email address is updated?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source