This project implements an authentication module in NestJS using JWT.
It provides endpoints for user registration, login, and protected routes.
- User registration (
/signup) - User login with email and password (
/signin) - JWT generation and return on login
- Token validation with
AuthGuard - Protected route
/mereturning user information from the token
UserEntity→ user representationSignUpDTOSignInDTO
POST /auth/signup→ registers a new userPOST /auth/signin→ authenticates user and returns JWTGET /auth/me→ returns the authenticated user data (protected)
signup()→ creates a new usersignin()→ validates credentials, generates JWTme()→ retrieves user info from token
canActivate()→ validates JWT and authorizes access to protected routes
- User sends name, email, and password
- Service hashes password and stores user
- Returns confirmation
- User sends email and password
- Service validates credentials
- Returns JWT token
- Request includes
Authorization: Bearer <token> AuthGuardvalidates JWT- Returns user information from token
You can visualize the flow in the diagram below (created with Excalidraw):
# install dependencies
npm install
# start development server
npm run start:dev