Overview
Budgetron uses BetterAuth for authentication, providing a secure and flexible authentication system with support for multiple providers. All authentication is integrated with the oRPC API layer for type-safe auth operations.Authentication Methods
Budgetron supports multiple authentication methods:- Email & Password - Traditional username/password authentication
- Google OAuth - Sign in with Google (optional)
- Custom OAuth - Generic OAuth 2.0 provider support (optional)
Configuration
Authentication is configured insrc/server/auth/config.ts:
Session Management
Getting the Session
The auth instance is a singleton that provides access to the current session:RPC Context
Every RPC request includes the user’s session in the context:Session Types
Authentication Flow
Sign Up
Procedure:api.auth.signUp
- User account is created
- Welcome email is sent automatically
- Email verification link is sent
- User is redirected to dashboard (if
autoSignIn: true)
Sign In (Email & Password)
Procedure:api.auth.signIn
Sign In (Social Provider)
Procedure:api.auth.signInWithSocial
Sign In (Custom OAuth)
Procedure:api.auth.signInWithOAuth
Get Current Session
Procedure:api.auth.session
Sign Out
Procedure:api.auth.signOut
Password Reset Flow
Request Password Reset
Procedure:api.auth.forgotPassword
Reset Password
Procedure:api.auth.resetPassword
Protected Procedures
Protected procedures automatically verify authentication and provide a typed session:Authorization Middleware
The authorization middleware ensures only authenticated users can access protected procedures:Client-Side Usage
React Component Example
Here’s a complete example of a password reset form:Checking Authentication
On the server side, you can require authentication:Email Verification
Automatic Email Sending
When a user signs up, BetterAuth automatically sends a verification email:Database Schema
BetterAuth uses four main tables:Users Table
Stores user account information:Sessions Table
Stores active user sessions:Accounts Table
Stores OAuth provider connections:Verifications Table
Stores verification tokens:Security Features
Token Expiration
- Password Reset Tokens: 15 minutes
- Email Verification Tokens: 15 minutes
- Delete Account Tokens: 15 minutes
Account Linking
Users can link multiple authentication providers to the same account:Disable Implicit Sign-Up
For OAuth providers, implicit sign-up can be disabled to require manual user creation:Error Handling
Authentication errors are handled consistently across all procedures:UNAUTHORIZED- Invalid credentials or no sessionFORBIDDEN- Feature disabled or email not verifiedBAD_REQUEST- Invalid input (e.g., weak password)CONFLICT- Email already exists
Next Steps
- API Overview - Learn about the complete API architecture
- Environment Variables - Configure authentication providers