nestjs-clone-bay docs
GitHub
GitHub
  • Introduction
  • Testing
  • API Reference

Function: CurrentUser

▸ CurrentUser(...dataOrPipes): ParameterDecorator

Inject authenticated user into method argument.

Accepts an optional options configuration object to allow a missing user. If options.nullable is set to true, this decorator will return null for a missing user. Otherwise throws HTTP 401.

Examples:

@Get("hello")
async hello(@CurrentUser() user: User) {
  // Will throw if user is not found.
}
@Get("hello")
async hello(@CurrentUser({ nullable: true }) user: User | null) {
  // `user` is `null` if not authenticated or not found. No error is thrown.
}

Parameters

NameType
...dataOrPipes(PipeTransform<any, any> | Type<PipeTransform<any, any>> | CurrentUserDecoratorOptions)[]

Returns

ParameterDecorator

User | null

Defined in

lib/src/decorators/current-user.decorator.ts:53

Edit this page
Last Updated: