-
Notifications
You must be signed in to change notification settings - Fork 481
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
Make express request injectable #1616
Comments
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 |
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 |
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 😄The text was updated successfully, but these errors were encountered: