Authentication Module¶
Overview¶
The Authentication module provides JWT-based authentication for the BidScript backend. It handles token validation and user authentication using JSON Web Tokens.
Module Structure¶
auth/
├── auth.module.ts # Module definition and configuration
├── auth.service.ts # Authentication business logic
├── jwt.guard.ts # JWT guard for protecting routes
├── jwt.strategy.ts # JWT verification strategy
└── current-user.decorator.ts # Decorator for accessing current user
Key Components¶
AuthModule¶
The root module that configures JWT authentication:
- Imports: PassportModule, JwtModule (configured with NEXTAUTH_SECRET)
- Providers: JwtStrategy, AuthService
- Exports: AuthService
AuthService¶
Provides authentication-related functionality.
JwtStrategy¶
Implements Passport strategy for JWT validation.
JwtGuard¶
Guards routes to ensure valid JWT authentication.
CurrentUser Decorator¶
Custom decorator for accessing the authenticated user in controllers.
Configuration¶
Authentication module is configured through environment variables: