You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
539 B
18 lines
539 B
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
import { Request } from 'express';
|
|
|
|
export interface AuthUser {
|
|
sub: string;
|
|
username: string;
|
|
tenantId?: string | null;
|
|
roles: string[];
|
|
permissions: string[];
|
|
regionIds: string[];
|
|
}
|
|
|
|
export const CurrentUser = createParamDecorator((data: keyof AuthUser | undefined, ctx: ExecutionContext) => {
|
|
const request = ctx.switchToHttp().getRequest<Request & { user?: AuthUser }>();
|
|
const user = request.user;
|
|
return data && user ? user[data] : user;
|
|
});
|