Performance: Role-based authorization
MEDIUM IMPACT
Role-based authorization affects server response time and client perceived latency by controlling access before processing requests fully.
canActivate(context: ExecutionContext) {
const request = context.switchToHttp().getRequest();
const userRoles = request.user.roles; // roles included in JWT token
if (!userRoles.includes('admin')) {
throw new ForbiddenException('Access denied');
}
return true;
}async canActivate(context: ExecutionContext) { const request = context.switchToHttp().getRequest(); const user = await this.userService.findUserById(request.user.id); if (!user.roles.includes('admin')) { throw new ForbiddenException('Access denied'); } return true; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetching roles from DB on each request | 0 | 0 | 0 | [X] Bad |
| Using roles from JWT token | 0 | 0 | 0 | [OK] Good |