Express JS Assignment- 4
Basic Questions
- Create two demo routes /auth-demo and /authz-demo to illustrate authentication (user login) vs authorization (role check).
- Implement session-based authentication using express-session.
- Store and retrieve a session value (e.g., userId) in Express.
- Generate a JWT token in Express, then decode and log its header, payload, and signature separately.
- Generate a JWT token using the jsonwebtoken library.
- Create an Express middleware that verifies JWT tokens.
- Protect a route /dashboard so only users with valid tokens can access.
- Implement login route that issues a JWT upon successful authentication.
- Add token expiry of 15 minutes while signing JWT.
- Decode a JWT token and display its payload.
- Build a route /stateless-demo that returns a response only if a valid JWT is sent, proving stateless session handling.
- Implement a logout route for session-based authentication.
- Implement both session‑based login (/session-login) and JWT‑based login (/jwt-login) in the same app to compare behavior.
- Create a roles field in a user object and print it on login.
- Add middleware that blocks users without the admin role.
- Create two routes: /rbac-dashboard accessible only by role=admin and /pbac-orders accessible only if permission delete:orders exists.
- Create an Express route /profile protected with role-based access.
- Secure the /login route by validating email and password.
- Store encrypted passwords using bcrypt in MongoDB.
- Implement a simple “forgot password” endpoint (just input email).
Intermediate Questions
- Configure session cookies to be HTTP-only and secure.
- Implement session storage using connect-mongo with MongoDB.
- Create a JWT with custom claims (like isPremiumUser: true).
- Write middleware that extracts JWT token from Authorization header.
- Implement refresh tokens along with access tokens in Express.
- Store refresh tokens in DB and validate them on token renewal.
- Revoke a JWT token manually (invalidate refresh token in DB).
- Write middleware that enforces role-based authorization for /admin.
- Extend role-based system to permission-based access control (PBAC).
- Implement a permission check: /orders/delete requires delete:orders.
- Secure an endpoint with multiple roles (e.g., admin OR moderator).
- Build a registration route that hashes passwords using bcrypt.
- Add password strength validation in registration.
- Implement a password reset route that verifies a reset token.
- Implement email-based password reset link with expiry.
- Implement two JWT tokens: one /short-token with 1‑minute expiry and another /refresh-token with 15‑minute expiry, then log expiry results.
- Create MySQL table users with encrypted password storage.
- Write an Express route to authenticate users from PostgreSQL.
- Implement MongoDB User model with schema validations.
- Secure sensitive routes (/settings, /billing) with token checks.
Advanced Questions
- Build a complete login + registration system with JWT authentication.
- Implement access + refresh token flow with automatic renewal.
- Add role-based and permission-based access to multiple endpoints.
- Build a middleware that checks role hierarchy (admin > manager > user).
- Implement two-factor authentication using OTP + JWT.
- Build a “forgot password” + “reset password” system with email + expiry.
- Secure JWT by storing refresh tokens in DB + blacklist revoked tokens.
- Implement session-based login with persistent store + auto-expiry.
- Integrate authentication system with MySQL, MongoDB, PostgreSQL and demonstrate login from each.
- Create a mini project:
- Registration + Login with JWT
- Role-based access control
- Refresh tokens
- Password reset
- Database integration