@helix/shared/decorators
Shared parameter decorators for extracting data from CLS context.
Overview
Provides decorators that extract authenticated user and tenant context from CLS (Continuation-Local Storage) set by middleware.
Installation
import { CurrentUser, TenantId } from '@helix/shared/decorators';
Available Decorators
CurrentUser
Extracts authenticated user context from CLS.
@Get('profile')
@UseGuards(JwtAuthGuard)
async getProfile(@CurrentUser() auth: any) {
return {
userId: auth.userId,
email: auth.user.email,
role: auth.role,
scopes: auth.scopes
};
}
TenantId
Extracts tenant ID from CLS context.
@Get('resources')
@UseGuards(JwtAuthGuard)
async getResources(@TenantId() tenantId: string) {
return this.service.findByTenant(tenantId);
}
Usage Patterns
// Pattern 1: User + Tenant
@Get('dashboard')
async getDashboard(
@CurrentUser() auth: any,
@TenantId() tenantId: string,
) {
return this.service.getDashboard(tenantId, auth.userId);
}
// Pattern 2: With Guards
@Roles('tenant_admin')
@UseGuards(JwtAuthGuard, RolesGuard)
@Delete(':id')
async delete(
@Param('id', UuidValidationPipe) id: string,
@TenantId() tenantId: string,
) {
return this.service.delete(tenantId, id);
}
CLS Integration
Decorators read from CLS context set by middleware:
- CurrentUser →
cls.get('auth') - TenantId →
cls.get('tenant').id
Works everywhere: HTTP, WebSocket, Cron, Workers.
License
Proprietary - CleverChain Limited