validate_user.js module exports four functions that handle different aspects of user verification across the TMT Platform. Use these after a user authenticates to confirm they have the correct access level before allowing them into protected areas.
Functions overview
| Function | Transport | Purpose |
|---|---|---|
validate_user_platform | HTTP (onRequest) | Check that an email exists in a specific collection |
validate_user_type | HTTP (onRequest) | Check that an email exists with a specific account_type |
setSessionId | Callable (onCall) | Store a session ID in Firestore and as a custom claim |
validate_user_email | HTTP (onRequest) | Confirm a collaborator’s email and activate their account |
validate_user_platform
Checks whether a user with a given email exists in a platform collection. Use this to verify that an authenticated user belongs to the platform before granting access.
Endpoint
Request
Firestore collection name to search in. One of
u_clients, u_collaborators, or u_staff.Email address to look up.
Response
User found:The function queries the collection for any document where
email equals the provided value. If a matching document exists, it responds with valido: true. If the snapshot is empty, it responds with valido: false.validate_user_type
Checks whether a user with a given email exists in a collection and has a specific account_type. Use this when different account types within the same collection have different access levels.
Endpoint
Request
Firestore collection name to search in.
Email address to look up.
The
account_type value the user must have (for example, admin, collaborator).Response
User found with matching type:setSessionId
Stores a session ID for an authenticated user in both Firestore (under users/{uid}) and as a Firebase custom claim. Use this to implement single-session enforcement — when a new session is set, existing sessions with a different sessionId can be rejected.
This function uses the Firebase Callable SDK (
onCall), not a plain HTTP request. Call it from a Firebase client SDK, not with a raw HTTP client.Callable function invocation (JavaScript)
Request data
A unique identifier for the current session. Generate this on your client after the user signs in.
What it does
- Verifies the caller is authenticated via Firebase Auth. Throws
unauthenticatedif not. - Writes
{ sessionId }tousers/{uid}in Firestore (merges with existing data). - Sets
{ sessionId }as a custom claim on the Firebase Auth user viasetCustomUserClaims.
Response
validate_user_email
Verifies that a collaborator’s email address matches what is stored in their u_collaborators document and, if it matches, sets their status to true. Use this as the final step in a collaborator email confirmation flow.
Endpoint
Request
The UID of the collaborator document in
u_collaborators.The email address to verify against the stored record.
What it does
- Validates that both
uid_userandemailare present. Returns400if either is missing. - Fetches the document at
u_collaborators/{uid_user}. Returns404if not found. - Compares the provided
emailagainstuserData.email. Returns403if they do not match. - Updates
statustotrueon the document. Returns200on success.
Response
Success (200):This function only operates on the
u_collaborators collection. It does not validate clients or staff accounts.