Function Signature
src/lib/actions/message/createMessage.ts:21
Parameters
Previous state object returned from the last invocation. Used by React’s
useActionState hook.Form data containing the message details
Return Value
Validation Schema
The function uses Zod for validation:Behavior
- Validation: Form data is validated against the Zod schema
- API Call: Makes a POST request to
{BACKEND_URL}/messages/create-one - Authentication: Uses Basic Auth with environment credentials
- Revalidation: Calls
revalidatePath("/")on success to refresh the home page - Error Handling: Returns structured error messages for validation, backend, or network errors
Usage Example
Backend Endpoint
POST/messages/create-one
Headers:
Authorization: Basic authenticationContent-Type: application/json