π§© Description
Build a reusable identity system with support for:
-
β
authId (safe external identifier)
-
β
internalAuthId (private DB reference)
-
β
OTP verification middleware (isOtpVerified)
-
β
verifyToken middleware for JWT/session validation
-
β
Middleware for isBlocked, isDeleted, isValidated, etc.
-
β
Global access in all modules (Todo, Product, Contact, etc.)
-
This is the foundation of FastKitβs identity and access management, allowing you to plug in access control to any route.
π§± Why This Is Important
-
πΌ Used in every application that needs secure user logic
-
π¦ Easy to reuse across multiple features/modules
-
π Centralizes authId, flags, and token/OTP verification
-
π Prevents boilerplate in every controller or route
π’ Difficulty Level: Intermediate β Advanced
You should be comfortable with:
β
Tasks
π Proposed File Structure
src/
|
β
βββ features/
β βββ Otp/
β βββ v1/
β βββ Otp.model.ts
β βββ Otp.middleware.ts # Middle Ware to Verify Otp , restrictToOwner.ts
β βββ Otp.constant.ts
βββ Otp.utils.ts
# other
π Auth.model.ts (Partial)
export interface IAuthUser {
authId: string;
internalAuthId: string;
isEmailVerified: boolean;
isOtpVerified: boolean;
isValidated: boolean;
isBlocked: boolean;
isDeleted: boolean;
...
}
vExample Usage:
router.get(
'/dashboard',
verifyToken,
FlagsUtils.check({ isValidated: true, isBlocked: false }),
dashboardController.show
);
π restrictToOwner.ts Middleware
export const restrictToOwner = (getOwnerAuthIdFn: (req) => string) => {
return (req, res, next) => {
if (req.user?.authId !== getOwnerAuthIdFn(req)) {
return res.status(403).json({ message: 'Unauthorized access' });
}
next();
};
};
Use in any module like Todo:
router.delete(
'/todo/:id',
verifyToken,
restrictToOwner(req => req.todo.authId),
todoController.delete
);
π¦ Auth.constant.ts
export const AUTH_ERRORS = {
BLOCKED: 'Account is blocked',
OTP_REQUIRED: 'OTP verification required',
VALIDATION_REQUIRED: 'User not validated',
UNAUTHORIZED: 'Unauthorized',
};
π README.md for This Module
β
Include:
Example:
import {
verifyToken,
checkFlags,
verifyOtp,
restrictToOwner,
} from 'fastkit-auth';
router.get(
'/user/profile',
verifyToken,
checkFlags({ isValidated: true }),
userController.getProfile
);
π― Expected Outcome
[x] Every feature uses authId for ownership checks
[x] Middleware for all common identity checks
[x] OTP validation logic fully reusable
[x] Cleaner, secure route protection
[x] Easy extension to new modules
ππ»ββοΈ Looking For
-
Help adding rate-limiting for OTP
-
Option to use Redis for OTP/session store
-
authId indexing support (Mongoose)
-
Tests for middleware logic
-
Add support for 2FA, IP/device validation in future
π Final Usage Pattern
router.post(
'/secure-data',
verifyToken,
verifyOtp,
checkFlags({ isValidated: true, isBlocked: false }),
SecureController.handle
);
π§© Description
β authId (safe external identifier)
β internalAuthId (private DB reference)
β OTP verification middleware (isOtpVerified)
β verifyToken middleware for JWT/session validation
β Middleware for isBlocked, isDeleted, isValidated, etc.
β Global access in all modules (Todo, Product, Contact, etc.)
This is the foundation of FastKitβs identity and access management, allowing you to plug in access control to any route.
π§± Why This Is Important
πΌ Used in every application that needs secure user logic
π¦ Easy to reuse across multiple features/modules
π Centralizes authId, flags, and token/OTP verification
π Prevents boilerplate in every controller or route
π’ Difficulty Level: Intermediate β Advanced
TypeScript + Express
JWT & token handling
Writing middleware
Using flags (boolean access control)
OTP flows (via DB or cache)
β Tasks
π Proposed File Structure
π Auth.model.ts (Partial)
vExample Usage:
π restrictToOwner.ts Middleware
π¦ Auth.constant.ts
π README.md for This Module
How authId works
When to use verifyToken
How to plug checkFlags middleware
How to restrict a route to logged-in, verified users
Example:
π― Expected Outcome
[x] Every feature uses authId for ownership checks
[x] Middleware for all common identity checks
[x] OTP validation logic fully reusable
[x] Cleaner, secure route protection
[x] Easy extension to new modules
ππ»ββοΈ Looking For
Help adding rate-limiting for OTP
Option to use Redis for OTP/session store
authId indexing support (Mongoose)
Tests for middleware logic
Add support for 2FA, IP/device validation in future
π Final Usage Pattern