next-safe-actionplayground
Overview
  • Home
Core
  • Core Actions
  • Validation Errors
  • Middleware
Hooks
  • React Hooks
  • Optimistic Updates
Forms
  • Form Integration
  • React Hook Form
Framework
  • Navigation & Framework
  • GitHub

Middleware

Logging, auth chains, error handling, and rate limiting.

Logging Middleware
Built-in logging middleware on the base action client that tracks execution time and logs inputs/outputs.

Check the server console for timing logs.

Result:
—
Auth Chain
Two chained .use() middleware calls building context: first adds userId, second adds sessionId.
Result:
—
Error Handling Middleware
Middleware that catches DatabaseError and transforms it into a user-friendly ActionError.
Result:
—
Rate Limiting Middleware
In-memory rate limiter that allows max 5 calls per 10 seconds. Click rapidly to trigger the limit.

Click more than 5 times in 10 seconds to see the rate limit error.

Result:
—