Quick Start - Better Auth & NATS Sync
🚀 Get Started in 5 Minutes
The Go backend relies on Better Auth (via the Bun monolith) for identity and NATS JetStream for data synchronization.1. Start Infrastructure
Ensure you have the following running:- PostgreSQL:
brew services start postgresql - Redis:
brew services start redis - NATS:
nats-server -js(JetStream enabled)
2. Configure Go Backend
Update yourbackend/go/.env file:
3. Run Migrations
Run GORM migrations to set up the PostgreSQL schema:4. Start the Server
Start the Go backend with hot reload (usingair):
5. Start Bun Monolith (Better Auth Provider)
In a separate terminal, start the Bun monolith which acts as the identity provider:6. Test Synchronization
- Register a User: Sign up a new user via the Bun monolith API or frontend.
- Watch NATS: The Bun monolith will publish a
user.createdevent touser.sync. - Check Go Logs: You should see:
- Verify PostgreSQL:
✅ Success Indicators
You’ll know it’s working when:- Go backend logs show successful connection to Postgres, Redis, and NATS.
- New users created in Better Auth automatically appear in the Go
userstable. - Sending a valid JWT to Go endpoints returns
200 OK.
📖 Full Documentation
- Architecture:
docs/backend/go/architecture/authentication.md - Troubleshooting:
docs/backend/go/guides/troubleshooting.md
🆘 Quick Troubleshooting
“Invalid token” → Check ifBETTER_AUTH_SECRET is identical in both Go and Bun.
“NATS Connection Refused” → Ensure nats-server -js is running.
“User not found” in Go → Check if the NATS consumer go-user-sync is active: nats consumer info user.sync go-user-sync.