When a user logs in or your app starts up, call this endpoint to register the device’s Firebase Cloud Messaging (FCM) token with the server. The server stores the token and uses it to push real-time notifications directly to the device — no polling required. If a token already exists for the givenDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/ecommerce-delivery/llms.txt
Use this file to discover all available pages before exploring further.
userId, it is updated in place and reactivated; otherwise a new record is created.
Endpoint
userId that matches the authenticated session on the client side.
Request body
The unique identifier of the user whose device is being registered. Used as the lookup key — only one active FCM token is stored per
userId at a time.The Firebase Cloud Messaging device token issued by the Firebase SDK on the client. This is a long opaque string that uniquely identifies the device/app installation. Tokens can be rotated by Firebase at any time; send the latest token whenever a new one is generated.
FCM tokens are device-specific — each physical device or browser instance gets its own token. Tokens can be invalidated or refreshed by the Firebase SDK at any time (e.g. after an app reinstall or a token rotation event). Re-call this endpoint with the new token whenever
onTokenRefresh fires in your app so that the server always holds a valid, active token.How the server stores the token
Internally, the server performs a MongoDBfindOneAndUpdate with upsert: true on the userId field:
- Existing user — the stored
fcmTokenis overwritten andactiveis set back totrue. - New user — a fresh
NotificationTokendocument is created withactivedefaulting totrue.
active flag is managed entirely by the server; you do not need to send it in the request body.
Response
200 — Success
Always
true when the token has been successfully stored or updated.400 — Missing fields
Returned when eitheruserId or fcmToken is absent from the request body.
A human-readable error message.
"Datos incompletos" means “incomplete data”.500 — Internal server error
Returned when an unexpected error occurs (e.g. a database failure).A human-readable error message indicating a server-side problem. Check server logs for the full stack trace.
When to call this endpoint
CallPOST /api/notification/register-token in the following situations:
- User login — immediately after a successful sign-in, fetch the current FCM token and register it so the server can associate it with the authenticated user.
- App startup — on each launch, retrieve the device token and re-register it to ensure it is still active and up-to-date.
- Token refresh — whenever the Firebase SDK fires a token-refresh event, register the new token immediately.
What the token is used for
Once registered, the server uses the FCM token to deliver push notifications for the following events:| Event | Who is notified |
|---|---|
| Order status changes (e.g. confirmed → shipped → delivered) | Customer whose order changed |
| Delivery tracking updates (driver location, ETA changes) | Customer awaiting delivery |
| New payment proof uploads | Admin users holding an admin FCM token |