Why JWT Tokens?
JWT tokens enable secure client-side access to Tinybird APIs: Use JWT tokens for:- Frontend applications that need direct API access
- Multi-tenant applications with row-level security
- Time-limited access with automatic expiration
- Scoped permissions for specific resources
- No need to expose admin tokens to clients
- Automatic expiration for security
- Fine-grained access control
- Row-level filtering with
fixed_params
Creating JWT Tokens
Use thecreateClient() API to create JWT tokens:
Scope Types
JWT tokens support three scope types:PIPES:READ
Grant read access to a specific pipe endpoint:DATASOURCES:READ
Grant read access to a datasource:DATASOURCES:APPEND
Grant append/ingest access to a datasource:Fixed Parameters
Usefixed_params to enforce row-level security on pipes:
- Are automatically injected into queries
- Cannot be overridden by the client
- Ensure users can only access their own data
- Perfect for multi-tenant applications
Example with Fixed Params
Pipe definition:Rate Limiting
Set rate limits on JWT tokens:Multiple Scopes
Grant access to multiple resources:Complete Examples
Next.js API Route
Create JWT tokens for authenticated users:React Client
Use JWT tokens in the frontend:Multi-Tenant SaaS
Implement organization-level isolation:Best Practices
Use short expiration times
Set expiration to 1-24 hours. Refresh tokens as needed rather than using long-lived tokens.
Always use fixed_params for user data
Never trust client-side parameters for user identification. Always use
fixed_params to enforce row-level security.Security Considerations
DO:- ✓ Create JWT tokens on the server-side only
- ✓ Use
fixed_paramsfor user/org isolation - ✓ Set short expiration times
- ✓ Implement rate limits
- ✓ Validate user sessions before creating tokens
- ✗ Never expose admin tokens to clients
- ✗ Never create JWT tokens in client-side code
- ✗ Never trust user-provided parameters for access control
- ✗ Never use JWT tokens without expiration
Next Steps
Type-Safe Client
Learn how to use the Tinybird client
Next.js Integration
Set up the SDK in Next.js projects