Send an anonymous message to any registered user by their username. This endpoint is intentionally public — callers do not need an account or a session cookie, which is what makes anonymous messaging possible. The server looks up the target user, verifies they are currently accepting messages, then pushes a new message object (withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dev0302/nextjs-project-1/llms.txt
Use this file to discover all available pages before exploring further.
content and a server-generated createdAt timestamp) into their embedded messages array and persists the change with user.save().
Method and URL
Authentication
None. This is a fully public endpoint. No session cookie, API key, or Authorization header is required or checked.Request Body
The request body must be JSON with the following fields:The username of the recipient. The server performs a
User.findOne({ username }) lookup, so the value must match exactly (case-sensitive) a registered account.The body of the anonymous message. Must be between 10 and 300 characters (inclusive). This constraint is enforced by the
messageSchema Zod schema on the client side — the route itself does not run this validation, so ensure the frontend validates with the same schema before calling this endpoint.Example Request
curl Example
Responses
201 — Message Sent
The message was successfully appended to the user’s inbox.403 — User Not Accepting Messages
The target user exists but has disabled their inbox via the/api/accept-messages toggle.
404 — User Not Found
No account exists with the providedusername.
500 — Internal Server Error
An unexpected error occurred during the database operation.Response Fields
true when the message was persisted; false on any error or rejection.A human-readable description of the outcome.
Notes
Content length validation is enforced client-side by the
messageSchema Zod schema (src/app/schemas/messageSchema.ts): content must be at least 10 characters and no more than 300 characters. The route itself does not call messageSchema.safeParse — it processes whatever content value arrives. Ensure your frontend validates with this schema before calling the endpoint.dbConnect() is called without await in this route (dbConnect() rather than await dbConnect()). This is a known bug in the source: the database connection is initiated but the route does not wait for it to complete before proceeding. In practice the connection is likely already cached, but be aware that on cold starts this could cause timing issues.