-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Task: JWT Authentication Setup in NestJS
Labels: enhancement, authentication, security, backend
Priority: High
Estimated Time: 4-6 hours
Description
We need to implement JWT (JSON Web Token) authentication in our NestJS application to secure API endpoints. This setup will allow users to authenticate and access protected routes using a token-based approach.
Acceptance Criteria
✅ JWT Module Integration
- Install and configure
@nestjs/jwtandpassport-jwt. - Set up a JWT strategy using Passport for token validation.
✅ Auth Module Structure
- Create an
AuthModulewith:AuthService(handles user validation & token generation).AuthController(login/signup endpoints).JwtStrategy(validates tokens in requests).
✅ Token Generation & Validation
- Generate access tokens upon successful login.
- Implement token expiration (e.g.,
1hfor access tokens). - Secure routes using
@UseGuards(AuthGuard('jwt')).
✅ Environment Configuration
- Store
JWT_SECRETand expiration time in.env. - Validate env variables using
@nestjs/config.
✅ API Documentation (Optional but Recommended)
- Add Swagger decorators (
@ApiBearerAuth(),@ApiUnauthorizedResponse) for authenticated routes.
Additional Notes
- Follow NestJS best practices for dependency injection.
- Ensure error handling for invalid/missing tokens.
- If time permits, consider refresh token implementation.
Reactions are currently unavailable