Loading content…
Loading content…
Develop a secure client-server authentication system featuring login, signup, password hashing, JWT creation, dynamic role checks, and refresh tokens.
Develop a secure client-server authentication system featuring login, signup, password hashing, JWT creation, dynamic role checks, and refresh tokens.
Backend and full-stack developers eager to master security pipelines, token lifecycles, and role-based route protection.
Business Objective
User data security is non-negotiable. The system must verify identities, store passwords securely using bcrypt hashing, issue JWT tokens stored in HttpOnly cookies, and block unauthorized endpoint access.
Core Features List
auth-system/ ├── src/ │ ├── middlewares/ │ │ ├── auth.ts # Token checks │ │ └── role.ts # Role filters │ ├── controllers/ │ │ └── authController.ts # Login/Signup logic │ ├── routes/ │ │ └── authRoutes.ts # Endpoint paths │ └── app.ts └── package.json
`Auth Controller` Component
Handles registration, password hashing, and user credential validation.
`Token Handler` Component
Generates access/refresh tokens and runs token validations.
`Security Wall` Component
Middlewares verifying token existence and filtering role permissions.
POST /api/auth/login
Request:
{
"email": "user@example.com",
"password": "SecurePassword123"
}
Response (200 OK):
Cookie: token=<JWT_VALUE>; HttpOnly; Secure
{
"success": true,
"user": { "id": "u1", "role": "admin" }
}CREATE TABLE users ( id VARCHAR(50) PRIMARY KEY, email VARCHAR(150) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, role VARCHAR(20) DEFAULT 'user', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Build users tables and write bcrypt helper utilities.
Code the login/signup controllers and token helpers.
Write verification middlewares protecting private routes.
Implement token rotations and role filter blocks.
💡 Set short expiry times (15 mins) on access tokens.
💡 Enforce password strength validations.
Click on any question to view the recommended architectural response for technical interviews.