mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 21:20:57 +00:00
Project Initialization
This commit is contained in:
11
packages/api-common/src/decorators/current-user.decorator.ts
Normal file
11
packages/api-common/src/decorators/current-user.decorator.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
|
||||
// TODO: integrate @edr/auth — this decorator currently returns whatever was
|
||||
// attached to request.user by the (not-yet-wired) auth middleware. Once the
|
||||
// auth package is integrated, replace this with the real user type.
|
||||
export const CurrentUser = createParamDecorator(
|
||||
(_data: unknown, ctx: ExecutionContext) => {
|
||||
const request = ctx.switchToHttp().getRequest();
|
||||
return request.user ?? null;
|
||||
},
|
||||
);
|
||||
8
packages/api-common/src/decorators/public.decorator.ts
Normal file
8
packages/api-common/src/decorators/public.decorator.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const IS_PUBLIC_KEY = 'isPublic';
|
||||
|
||||
// TODO: integrate @edr/auth — pair with the JwtAuthGuard from the auth package
|
||||
// so it skips authentication for routes marked @Public(). Until then, this is
|
||||
// just metadata.
|
||||
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
||||
8
packages/api-common/src/decorators/roles.decorator.ts
Normal file
8
packages/api-common/src/decorators/roles.decorator.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const ROLES_KEY = 'roles';
|
||||
|
||||
// TODO: integrate @edr/auth — pair this metadata with a RolesGuard from the
|
||||
// auth package. Until then, this decorator only sets metadata and has no
|
||||
// runtime effect.
|
||||
export const Roles = (...roles: string[]) => SetMetadata(ROLES_KEY, roles);
|
||||
Reference in New Issue
Block a user