Overview
Modelence authentication includes:- Email/Password Authentication - User signup and login with email and password
- Session Management - Secure session handling with automatic token rotation
- User Management - User profile and role management
- Email Verification - Optional email verification for new signups
- Password Reset - Secure password reset flow with email tokens
- Hooks - Add custom handlers that run after login or signup
- Rate Limiting - Built-in protection against brute force attacks
- Google Sign-In - OAuth authentication with Google accounts
How Authentication Works
Session Management
When a user visits your application, Modelence automatically creates a session:- Session Creation - A secure session token is generated using cryptographically random bytes
- Token Storage - The session token is stored in the database and sent to the client
- Automatic Expiration - Sessions expire after 7 days of inactivity
- Heartbeat Updates - Active sessions are automatically renewed through periodic heartbeat requests
_modelenceSessions collection and tracked with the following properties:
User Authentication Flow
Signup Process
When a user signs up with email and password:- Validation - Email format and password strength are validated
- Duplicate Check - System checks if email already exists
- Password Hashing - Password is securely hashed using bcrypt (never stored in plain text)
- User Creation - User record is created in the
_modelenceUserscollection - Session Linking - The session is linked to the new user
- Email Verification (Optional) - If enabled, a verification email is sent
Login Process
When a user logs in:- Credential Verification - Email and password are validated against stored credentials
- Session Update - Current session is linked to the authenticated user
- User Data - User information is returned to the client
- State Update - Client-side session state is updated
Basic Implementation
Client-Side Usage
Signup
Login
Logout
Accessing Current User
API Reference
Client Functions
- signupWithPassword - Sign up with email and password
- loginWithPassword - Log in with email and password
- logout - Log out current user
- useSession - Access current user session
- verifyEmail - Verify email with token
- sendResetPasswordToken - Request password reset
- resetPassword - Reset password with token
Server Types
- AuthConfig - Authentication configuration
- UserInfo - User information type
- dbUsers - User database collection
Error Types
- AuthError - Authentication errors
- ValidationError - Validation errors
- RateLimitError - Rate limit errors