Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator for authenticated user #43

Closed
jalorenz opened this issue Apr 11, 2021 · 3 comments
Closed

Decorator for authenticated user #43

jalorenz opened this issue Apr 11, 2021 · 3 comments

Comments

@jalorenz
Copy link
Contributor

jalorenz commented Apr 11, 2021

Hi John,

first of all thanks a lot for this package :)

While using your package i asked myself, how can i receive user information like the user id. After digging the code i saw that you already assign the user information to the request object. Maybe you should write that in the documentation because other people might have the same question.

P.S.: the following decorator might be some syntax sugar:

import { createParamDecorator, ExecutionContext } from "@nestjs/common"

export const AuthenticatedUser = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {
  const req = ctx.switchToHttp().getRequest()
  return req.user
})

Have a nice day! :)

@ferrerojosh
Copy link
Owner

Hello! Feel free to do a pull request for this. Would gladly accept this decorator into the library.

@ferrerojosh ferrerojosh mentioned this issue Apr 12, 2021
@ferrerojosh
Copy link
Owner

I added it myself since I wanted to release 1.5.0 today.

@erald14
Copy link

erald14 commented Jul 9, 2021

@ferrerojosh good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants