Overview
Watch mode automatically monitors yourauth.ts configuration file and reloads the Better Auth Studio server when changes are detected. This provides a seamless development experience when iterating on your authentication setup.
Enabling Watch Mode
Start the studio with the--watch flag:
How It Works
Change Detection
When you save changes to your auth config file, the studio detects them immediately.
Server Reload
The server automatically:
- Closes the current instance
- Reloads the auth configuration
- Restarts the server
- Maintains the same port and host
WebSocket Integration
Watch mode uses WebSocket to provide real-time updates to the browser:Connection Lifecycle
Status Messages
The studio sends status updates during reload:up_to_date - Server Ready
up_to_date - Server Ready
refreshing - Reload in Progress
refreshing - Reload in Progress
error - Reload Failed
error - Reload Failed
Change Events
Configuration
With Custom Config Path
Watch mode works with custom config paths:With Other Options
Combine watch mode with other CLI options:Terminal Output Examples
Successful Reload
Failed Reload
Auto-Detection Warning
If the auth config file cannot be located:Heartbeat & Connection Management
Watch mode maintains WebSocket connections with automatic heartbeat:- Keeps connections alive
- Detects disconnected clients
- Automatically cleans up closed connections
Use Cases
Plugin Development
Test Better Auth plugins in real-time as you develop them.
Provider Configuration
Iterate on OAuth provider settings and see changes immediately.
Database Changes
Switch between database adapters and test configurations.
Security Settings
Adjust security options and verify them instantly.
Best Practices
During Active Development
For Production Testing
For production deployments:- Use self-hosting setup
- Disable watch mode
- Implement proper deployment strategies
Troubleshooting
Watch Mode Not Working
Config file not detected
Config file not detected
Problem:
⚠ Unable to locate your auth config fileSolution:Reload keeps failing
Reload keeps failing
Problem:
✖ Reload failed - Unable to reload auth configurationSolutions:- Check for syntax errors in
auth.ts - Verify all imports are valid
- Check terminal for detailed error messages
- Ensure database connection is still active
Browser not updating
Browser not updating
Problem: UI doesn’t reflect config changesSolutions:
- Check browser console for WebSocket errors
- Verify WebSocket connection is established
- Try manually refreshing the page
- Restart the studio server
Multiple rapid changes
Multiple rapid changes
Problem: Server reloads too frequentlySolutions:
- Wait for reload to complete before making more changes
- Disable auto-save in your editor temporarily
- The studio includes a 75ms debounce to prevent excessive reloads
WebSocket Connection Issues
If WebSocket connections fail:- Check firewall settings - Ensure WebSocket connections are allowed
- Verify port availability - Make sure the port isn’t blocked
- Browser compatibility - Use a modern browser with WebSocket support
- Network proxy - Some proxies may block WebSocket connections
Graceful Shutdown
Watch mode handles shutdown gracefully:- Closes the file watcher
- Terminates WebSocket connections
- Shuts down the HTTP server
- Exits cleanly
Performance Considerations
File Watching
- Efficient: Uses
chokidarfor optimal file system monitoring - Selective: Only watches the auth config file, not the entire project
- Low overhead: Minimal CPU/memory impact during idle periods
Reload Speed
Typical reload times:- Detection: <10ms (instant)
- Server restart: 50-200ms
- Config reload: 100-500ms (depends on complexity)
- Total: Usually under 1 second
Next Steps
CLI Usage
Explore all CLI options and commands
Custom Branding
Customize studio appearance
Troubleshooting
Common issues and solutions
Self-Hosting
Production deployment guide