This project was developed as part of my internship assignment at Zenmonk Software and Services (FUNIBER).
It implements secure session-based authentication with session logs, WebSockets-based real-time OTP validation, and session management (max 2 devices at a time).
-
User Authentication
- Signup for new users
- Login with credentials
- Session-based authentication with 60-minute validity
- Automatic session expiry after 60 minutes of inactivity
-
Session Management
- Only one active session per user by default
- If a second login attempt is made:
- Generate a 6-digit OTP on the second device
- Prompt the first device with an input box via WebSocket
- Validate OTP in real-time
- Allow second device login only if OTP matches
- At most 2 active sessions allowed
- If a 3rd login attempt is made β Show error: "Already 2 sessions active"
-
Dashboard
- Redirects users to dashboard after login
- Shows session logs of all previous sessions:
- Device
- IP address
- Time of login
-
Security
- Session-based authentication (not JWT)
- Real-time communication handled via WebSockets
- Concurrent session validation
- Frontend: Next.js (React), TypeScript, CSS
- Backend: Nest.js, Node.js
- Database: PostgreSQL (TypeORM)
- Real-Time: WebSockets
- Authentication: Session-based
git clone https://github.com/Ashugithubb/sessionsManegment.git cd sessionsManegment
For Frontend (Next.js):
cd frontend
npm install
For Backend (Nest.js):
cd backend
npm install
Create a .env
file inside backend/
with the following:
DATABASE_URL=postgres://user:password@localhost:5432/yourdb
SESSION_SECRET=your-secret-key
PORT=4000
Run backend (Nest.js):
npm run start:dev
Run frontend (Next.js):
npm run dev
The app will be available at:
- Frontend:
http://localhost:3000
- Backend API:
http://localhost:4000
- User Signup/Login β Session created (valid 60 mins).
- Dashboard β Displays past session logs (device, IP, time).
- Second Device Login β OTP generated on device 2, verified via device 1 using WebSockets.
- Third Device Login β Blocked with error message.
- Signup/Login functionality with sessions
- 60 min session validity with inactivity timeout
- Session logs with device, IP, and timestamp
- Real-time OTP validation using WebSockets for multiple devices
- Max 2 concurrent sessions per user