- Private Components: Keep your business logic and internal components secure
- Team-Specific Resources: Give different teams different components
- Access Control: Limit who can see sensitive or experimental components
- Usage Analytics: See who’s using which components in your organization
- Licensing: Control who gets premium or licensed components
Common Authentication Patterns
Token-Based Authentication
The most common approach uses Bearer tokens or API keys:components.json
.env.local
API Key Authentication
Some registries use API keys in headers:components.json
Query Parameter Authentication
For simpler setups, use query parameters:components.json
https://registry.company.com/button.json?token=your_token
Server-Side Implementation
Here’s how to add authentication to your registry server:Next.js API Route Example
app/api/registry/[name]/route.ts
Express.js Example
server.js
Advanced Authentication Patterns
Team-Based Access
Give different teams different components:api/registry/route.ts
User-Personalized Registries
Give users components based on their preferences:Temporary Access Tokens
Use expiring tokens for better security:Multi-Registry Authentication
With namespaced registries, you can set up multiple registries with different authentication:components.json
- Mix public and private registries
- Use different authentication per registry
- Organize components by access level
Security Best Practices
Use Environment Variables
Never commit tokens to version control. Always use environment variables:.env.local
components.json:
Use HTTPS
Always use HTTPS URLs for registries to protect your tokens in transit:Add Rate Limiting
Protect your registry from abuse:Rotate Tokens
Change access tokens regularly:Log Access
Track registry access for security and analytics:Testing Authentication
Test your authenticated registry locally:Error Handling
The shadcn CLI handles authentication errors gracefully:- 401 Unauthorized: Token is invalid or missing
- 403 Forbidden: Token lacks permission for this resource
- 429 Too Many Requests: Rate limit exceeded
Custom Error Messages
Your registry server can return custom error messages in the response body, and the CLI will display them to users:Next Steps
To set up authentication with multiple registries and advanced patterns, see the Namespaced Registries documentation. It covers:- Setting up multiple authenticated registries
- Using different authentication per namespace
- Cross-registry dependency resolution
- Advanced authentication patterns