When a user opens the in-ride chat screen, this endpoint loads the full message history for the thread before live events begin streaming. Call it once on screen mount to populate prior messages, then subscribe to theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/Crucidrive---APP/llms.txt
Use this file to discover all available pages before exploring further.
message_received WebSocket event to receive any messages sent afterwards without re-fetching.
Access
The requesting user must be authenticated via theauthMiddleware and must be a registered member of the target thread. Membership is enforced through the thread_members table — if the user’s ID is not present for the given threadId, the server returns 403 before any message data is read.
Path parameter
UUID of the chat thread. This value is returned in the
aceptarViaje response
when a driver accepts a ride and the thread is created. Threads are unique
per ride (threads.viaje_id is a 1:1 foreign key into public.viajes).Response — 200 OK
Returns an array of message objects ordered bycreated_at ASC. Each object includes a nested perfiles sub-object with sender profile data resolved via a Supabase join on sender_id.
Message UUID — primary key of the
messages table row.UUID of the parent chat thread. Matches the
threadId path parameter.UUID of the user who sent the message. Foreign key into
public.perfiles.Plain-text message body. Whitespace is trimmed before storage.
ISO 8601 timestamp set by the database at insert time, e.g.
2024-11-15T14:23:01.000Z.Nested sender profile resolved from the
public.perfiles table via the
sender_id foreign key.Example response
Membership validation
Before any message data is read, the controller calls thecheckThreadMembership(threadId, userId) helper from supabaseHelpers.js. This function queries public.thread_members using a maybeSingle() selector — if a row matching both thread_id and user_id exists, the request proceeds; otherwise the server short-circuits with a 403. This mirrors the Row Level Security policy on the messages table in Supabase, providing defense in depth at both the application and database layers.
Error cases
| Status | Condition |
|---|---|
400 | threadId is missing from the path parameters |
403 | Authenticated user is not a member of the thread (thread_members lookup returned no row) |
500 | Database error while executing the thread_members membership check |
400 | Database error while fetching messages from the messages table |