Overview
The authentication system provides:- Email/password authentication with validation
- Email verification for new accounts
- Password reset flow
- Session management with automatic refresh
- Rate limiting for security
- Organization support with invitations
- Admin impersonation capabilities
- Comprehensive audit logging
Authentication Setup
The auth configuration is centralized insrc/lib/auth/auth.ts. Two instances are created:
- API Instance (async): Used by the Astro application
- CLI Instance (sync): Used by command-line tools and migrations
Core Configuration
Plugins
Concordia uses three Better Auth plugins to extend functionality.Username Plugin
Enables username-based authentication in addition to email:- Allows users to sign in with username or email
- Usernames are validated during signup
- Unique constraint enforced at database level
Organization Plugin
Provides multi-tenant organization support:auth.ts:318-334):
Admin Plugin
Enables administrative capabilities:- User impersonation for support
- Direct user management
- Access to all organization data
Email Verification
Email verification is required for all new accounts.Verification Flow
Email template (from
auth.ts:78-90):
Password Reset
Users can reset their password via email.Reset Flow
Reset email template (from
auth.ts:65-76):
Session Management
Sessions are managed with secure cookies and automatic refresh.Session Configuration
- Sessions expire after 7 days of inactivity
- Session tokens are automatically refreshed every 24 hours
- Cookie cache reduces database queries
- Absolute timeout ensures re-authentication after 7 days
Session Security
- Secure cookies (HTTPS only in production)
- Origin checking enabled
- Trusted origins whitelist
- IP tracking for audit logs
- Bearer token invalidation on logout
Rate Limiting
Built-in rate limiting protects against brute force attacks.- Global: 100 requests per minute per IP
- Sign in: 5 attempts per 15 minutes
- Sign up: 10 registrations per hour
Post-Signup Hooks
When a user signs up, several actions occur automatically:Automatic Profile Creation
Automatic Profile Creation
Every new user gets a profile with:
- Auto-generated username (from email if not provided)
- Preferred language set to French (“fr”)
- Empty bio and optional full name
Wallet Initialization
Wallet Initialization
Every user receives a digital wallet:
- Starting balance: 0.00 EUR
- Ready for transactions, bookings, and donations
Default Role Assignment
Default Role Assignment
All users are automatically granted the citizen role:
- Enables core platform features
- Additional roles can be granted by admins
Audit Logging
Audit Logging
Signup events are logged:
- User ID and email recorded
- Timestamp captured
- Available for compliance and debugging
Audit Logging
All authentication events are logged to theaudit_log table.
Login Success
Login Failure
signup- New user registrationlogin_success- Successful authenticationlogin_failed- Failed login attempt (with IP and user agent)