Reputation: 1275
I have a Flutter mobile application and I am using Firebase authentication. I have decided to use email template for verifying user email. In the backend, I call generateEmailVerificationLink(email ,actionCode) to create an email verification link, then I pass the link to a good looking email template and send it to the user.
I would like to do the same thing for updating user email. But I am not sure which function to call in the backend to create the proper link that I need to pass to the email temple. The mode in the action code should be "verifyAndChangeEmail"
Does any one know?
I found this link https://firebase.google.com/docs/auth/admin/email-action-links
but it does not say how to generate a link for updating user email. Does that mean that I can't have a custom email for updating user email??
Please help.
Upvotes: 0
Views: 1077
Reputation: 83113
You can use the same generateEmailVerificationLink()
method, and, in the page opened via the link, you need to trigger, in the back-end, the updateUser()
method of the Admin SDK.
More concretely:
applyActionCode()
, as shown in the code found in this page in the Firebase doc (see "4. Handle email address verification by calling applyActionCode
.").then((resp) => {...})
block of this page, implement a call to a callable Cloud Function in which you use the updateUser()
method to update the user's email. In the callable cloud function you must check that the uid
(User ID) that you pass to the updateUser()
method is the uid
of the caller (with const uid = context.auth.uid;
see the doc).Upvotes: 2