Better Auth
Integrate Rivet with Better Auth for authentication
Better Auth provides a comprehensive authentication solution that integrates seamlessly with Rivet Actors using the onAuth
hook.
View Example on GitHub
Check out the complete example
Installation
Install Better Auth alongside Rivet:
Note
This example uses SQLite to keep the example. In production, replace this with a database like Postgres. Read more about configuring your database in Better Auth.
Backend Setup
Configure Better Auth
Create your authentication configuration:
Generate & Run Migrations
Create and apply the database schema:
Create Protected Actor
Use the onAuth
hook to validate sessions:
Setup Server with CORS
Configure your server to handle Better Auth routes and Rivet:
Frontend Integration
Setup Better Auth Client
Create a Better Auth client for your frontend:
Authentication Form
Create login/signup forms:
Integrate with Rivet
Use authenticated sessions with Rivet:
Advanced Features
Role-Based Access
Add role checking to your actors:
Session Management
Handle session expiration gracefully:
Production Deployment
For production, you'll need a database from a provider like Neon, PlanetScale, AWS RDS, or Google Cloud SQL.
Configure your production database connection:
Set the following environment variables for production:
Read more about configuring Postgres with Better Auth.
Tip
Don't forget to re-generate & re-apply your database migrations if you change the database in your Better Auth config.