mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-09 14:29:08 +00:00
26 lines
708 B
TypeScript
26 lines
708 B
TypeScript
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
|
|
import ErrorBuilder from '../utils/ErrorBuilder';
|
|
import ErrorCodes from '../utils/errorCodes';
|
|
|
|
export interface RequestUser {
|
|
user_id: string;
|
|
username: string;
|
|
permissions: number[];
|
|
customer_id: string;
|
|
customer_name: string;
|
|
customer_tier: string;
|
|
access_token: string;
|
|
}
|
|
|
|
export const User: (options?: { required?: boolean }) => ParameterDecorator =
|
|
createParamDecorator((options: any, ctx: ExecutionContext) => {
|
|
const request = ctx.switchToHttp().getRequest();
|
|
|
|
if (!request.user && options?.required) {
|
|
throw new ErrorBuilder(ErrorCodes.AUTH.UNAUTHORIZED);
|
|
}
|
|
|
|
return request.user;
|
|
});
|