Skip to main content
Updates a user’s email address in Firebase Authentication and then updates the matching document in the specified Firestore collection.

Endpoint

POST https://{region}-{project}.cloudfunctions.net/update_email

Request body

All parameters are nested under a data key.
data.uid
string
required
The Firebase Authentication UID of the user whose email is being updated.
data.email
string
required
The new email address to set.
data.emailold
string
required
The user’s current (old) email address. Used to locate the Firestore document to update.
data.collection
string
required
The Firestore collection containing the user’s document. One of u_clients, u_collaborators, or u_staff.

Example

curl -X POST https://{region}-{project}.cloudfunctions.net/update_email \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "uid": "abc123xyz",
      "email": "[email protected]",
      "emailold": "[email protected]",
      "collection": "u_clients"
    }
  }'

What it does

  1. Calls auth.updateUser(uid, { email }) to update the email in Firebase Authentication.
  2. Queries {collection} for documents where email == emailold.
  3. For each matching document, updates:
    • email → the new email address
    • date.last_updateTimestamp.now()

Response

message
string
Result description.
status
number
200 on success, 400 on error.
data
object
Success (200):
{
  "message": "Usuario: Email Actualizado!",
  "status": 200,
  "data": { "update": true }
}
Error (400):
{
  "message": "Usuario: Email No Actualizado!!",
  "status": 400,
  "data": {
    "update": false,
    "error": {
      "code": "auth/email-already-exists",
      "message": "The email address is already in use by another account."
    }
  }
}
If the Firebase Authentication update fails, the Firestore document is not modified. If the Auth update succeeds but the Firestore update fails, the function still returns 200. Ensure your application handles this potential inconsistency.

Build docs developers (and LLMs) love