File size: 417 Bytes
b26189e
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import type { User } from '@prisma/client';

/** Injects the request's authenticated DB user (or null in anonymous mode). */
export const CurrentUser = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): User | null => {
    const req = ctx.switchToHttp().getRequest<{ user?: User | null }>();
    return req.user ?? null;
  },
);