Closed sourceful-mia closed 2 months ago
Hello there sourceful-mia π
Thank you for opening your very first issue in this project.
We will try to get back to you as soon as we can.π
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Hi @sourceful-mia
you need to define a new Request interface like and use a express or tsoa middleware to intercept the request and inject what you want :
import { Request } from 'express'
export interface baseHttpRequest extends Request {
jwtUser?: IUser | null
clientIp?: string
deviceType?: string
appVersion?: string // for andriod or IOS app version
userAgent?: string
...
middlewaresData?: {
article?: IArticle // For example
}
}
And next you can replce your @Request() private request
by @Request() private baseHttpRequest
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
I am looking to get the user claims from my JWT so that I can get user id & name. I'd like to make this available everywhere as an injectable service, to avoid every controller route having to worry about passing the request down, and reduce the amount of parameters that need to go through every function.
Possible Solution
I've tried to create a UserService where I inject the request, but it doesn't work:
A couple of other ideas:
I really like tsoa and how it reduces the amount of
(req, res) => {}
functions in regular express servers, so I'm keen to avoid having to do this again with this library π