Overview
Your Finance App implements a robust authentication system supporting both local authentication (email/password) and OAuth providers (Google). The system uses JWT tokens for stateless authentication and bcrypt for password hashing.Authentication Flow
Module Structure
The authentication module is organized as follows:Auth Module Configuration
Registration Flow
Registration Endpoint
Registration Service Logic
Registration uses a database transaction to ensure atomicity - if asset initialization fails, the user creation is rolled back.
Password Hashing
Passwords are hashed using bcrypt with 10 salt rounds:Login Flow
Login Endpoint
Login Service Logic
JWT Strategy
Token Generation
Token Validation
The JWT strategy validates tokens on every protected request and attaches the user to
req.user.Guards
JWT Auth Guard
Protects routes requiring authentication:Roles Guard
Implements role-based access control:Google OAuth Integration
Google Strategy
Google OAuth Flow
OAuth Endpoints
Google User Validation
Custom Decorators
CurrentUser Decorator
Extracts authenticated user from request:Roles Decorator
Defines required roles for endpoints:Security Best Practices
Password Hashing
Bcrypt with 10 salt rounds prevents rainbow table attacks
Token Expiration
JWTs expire after 7 days, requiring re-authentication
HTTPS Only
Tokens transmitted over encrypted connections in production
Environment Secrets
JWT secrets stored in environment variables, never committed
Configuration Variables
Required environment variables:Token Refresh Strategy
Currently, tokens are valid for 7 days. For enhanced security, implement refresh tokens:Refresh token rotation provides better security while maintaining user experience.
Next Steps
Architecture Overview
Understand the overall system architecture
API Endpoints
Explore authentication API endpoints
