Skip to main content
The create_staff function creates a Firebase Authentication user and writes a document to the u_staff Firestore collection. Staff are internal platform operators with access to administrative functions.

Endpoint

POST https://<region>-<project>.cloudfunctions.net/create_staff

Request body

All fields are nested under a top-level data key.

Required fields

data.name
string
required
Full name of the staff member.
data.email
string
required
Email address. Used as the Firebase Authentication login credential.
data.password
string
required
Initial password for the Firebase Authentication account. Not stored in Firestore.

Optional fields

data.phone
string
Contact phone number.
data.status
string
Account status.
data.account_type
string
Account classification used for role-based access checks.
data.id
string
Government-issued identification number.
data.id_type
string
Type of identification document.
data.commercial_name
string
Commercial or display name for the staff member.

Address fields

data.city
string
City. Stored under address.city in Firestore.
data.country
string
Country. Stored under address.country in Firestore.
data.line
string
Street address line. Stored under address.line in Firestore.
data.zip_code
string
Postal code. Stored under address.zipcode in Firestore.

Example request

{
  "data": {
    "name": "Ana Torres",
    "email": "[email protected]",
    "password": "SecurePass123!",
    "phone": "+58-212-555-0300",
    "status": "active",
    "account_type": "admin",
    "id": "V-22334455",
    "id_type": "cedula",
    "commercial_name": "TMT Operations",
    "city": "Caracas",
    "country": "Venezuela",
    "line": "Torre Financiera, Piso 10",
    "zip_code": "1010"
  }
}

What is written to Firestore

The function writes a document to u_staff/{uid} with the following structure:
{
  "name": "Ana Torres",
  "email": "[email protected]",
  "phone": "+58-212-555-0300",
  "status": "active",
  "account_type": "admin",
  "id": "V-22334455",
  "id_type": "cedula",
  "address": {
    "city": "Caracas",
    "country": "Venezuela",
    "line": "Torre Financiera, Piso 10",
    "zipcode": "1010"
  },
  "commercial_name": "TMT Operations",
  "security_2fa": {
    "status": false,
    "type": "email"
  },
  "timezone": "",
  "date": {
    "create": "<Firestore Timestamp>",
    "last_access": "",
    "last_update": ""
  }
}
The document ID in Firestore is the Firebase Authentication UID. The password field is never written to Firestore.

Staff-specific fields

security_2fa

All staff documents are initialized with a security_2fa object:
FieldDefault valueDescription
security_2fa.statusfalseWhether 2FA is currently enabled for this account.
security_2fa.type"email"The 2FA delivery method. Initialized to "email".
Update security_2fa.status to true once the staff member has completed 2FA enrollment.

timezone

The timezone field is initialized as an empty string. Update it after creation with the staff member’s local IANA timezone identifier (for example, "America/Caracas").

Response

Success

message
string
Confirmation message including the new UID.
status
number
200 on success.
data
object
{
  "message": " Ingresado con el ID: ghi789rst .",
  "status": 200,
  "data": {
    "uid": "ghi789rst"
  }
}

Error

{
  "message": "Error creando nuevo usuario:",
  "status": 400,
  "data": {
    "error": {
      "code": "auth/email-already-exists",
      "message": "The email address is already in use by another account."
    }
  }
}
If auth.createUser() fails, no Firestore document is written. The function returns 400 and stops processing.

Build docs developers (and LLMs) love