-
Notifications
You must be signed in to change notification settings - Fork 73
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
Type-safe request extensions #317
Comments
Hi @sjanota! |
I was trying to write a simple authentication middleware, similar to JWT. I was able to write to middleware without a problem but I was stuck on how to safely pass the user data down the stream. I've noticed that in JWT middleware user is assigned to request and thus is considered One thing I was trying to do was:
Then my middleware was of type |
One additional question - did you try to compose it directly inside the effect? see here |
No, I made it a global middleware. I'll play with the Effect approach later today. |
Took me a while, but I'm back on this. So, I've declared my custom request and middleware like this:
Then in an effect, I add it using
Here One of the reasons is that
the compiler properly resolves type of It works if I specify the type explicitly though: Also, I've found that |
I pressed "Comment" one test too early :D. I noticed that both Looks like
And However, it would be great if one could achieve the same thing with |
I have to analyze this topic deeper but the problem that you described is already known. For now const setUserProperties$ = r.pipe(
r.matchPath('/:id'),
r.matchType('PUT'),
r.useEffect(req$ => req$.pipe(
use(authenticate$), // 👈
)),
); |
Is your feature request related to a problem? Please describe.
Right now
HttpRequest
is can be assigned any property. Thanks to that you can pass custom properties down the stream as middleware-jwt does.However, custom properties are of type
any
. I can't see a way to make them type-safe. Am I missing something?Describe the solution you'd like
I'd like to pass custom properties in a type-safe manner as it is done with
params
,query
, andbody
.Describe alternatives you've considered
I tried to extend the
HttpRequest
type and make my middleware return the extended version, but with no success.Additional context
The text was updated successfully, but these errors were encountered: