Configuration
Access control is configured in yourstudio.config.ts file:
studio.config.ts
Access Options
Array of user roles that are allowed to access Studio. Users must have one of these roles in their Better Auth user record.
Array of email addresses that are allowed to access Studio. Only users with these email addresses can authenticate.
Session duration in milliseconds. Controls how long admin sessions remain valid before requiring re-authentication.Default:
3600000 (1 hour)Secret key used for signing admin session tokens. Should be a strong, random string stored in environment variables.
Access Control Methods
Role-Based Access
Restrict access by user roles. Users must have one of the specified roles in their user record:studio.config.ts
Roles are checked against the
role field in your Better Auth user table. Ensure your user schema includes this field.Email Allowlist
Restrict access to specific email addresses:studio.config.ts
Combined Access Control
Use both roles and email allowlist for maximum security:studio.config.ts
When both
roles and allowEmails are configured, users must satisfy both conditions to gain access.TypeScript Type Definition
Environment Variables
Store sensitive configuration in environment variables:.env
studio.config.ts
Security Best Practices
Generate a Strong Secret
Recommended Session Durations
- High Security: 30 minutes (
1800000ms) - Standard: 1 hour (
3600000ms) - Convenience: 4 hours (
14400000ms)
Authentication Flow
When a user attempts to access Studio:- Studio checks if an admin session exists
- If no session, redirects to login
- User authenticates with Better Auth
- Studio validates the user’s role and/or email
- If authorized, creates an admin session
- User gains access to Studio
Troubleshooting
Access Denied Error
If you’re seeing “Access Denied” errors:- Verify the user’s email is in
allowEmails(if configured) - Check the user’s role matches one in
roles(if configured) - Ensure the user has successfully authenticated with Better Auth
- Check browser console for specific error messages
Session Expiration
If sessions expire too quickly or slowly:- Adjust
sessionDurationin your config - Clear browser cookies and re-authenticate
- Verify system clock is synchronized