-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
last middlewareEndpoints wins #4449
Comments
if it's not a bug but an expected behavior, this should be documented |
Apis in effect that "wrap" things, generally flow from the bottom up. If you want to apply specific middleware to specific endpoints then you can use .middleware on the endpoint itself. |
I had to take some time to understand your message because I think there is a misunderstanding. what I see const ExampleApi = HttpApiGroup.make("examples")
.add(HttpApiEndpoint.get("first", "/first").addSuccess(ExampleResponseDto)) // *protected by oauth2*
.middlewareEndpoints(AuthenticationApiKey)
.add(HttpApiEndpoint.get("second", "/second").addSuccess(ExampleResponseDto)) // protected by oauth2
.middlewareEndpoints(AuthenticationOauth2)
.add(HttpApiEndpoint.get("third", "/third").addSuccess(ExampleResponseDto)); // not protected what I expect const ExampleApi = HttpApiGroup.make("examples")
.add(HttpApiEndpoint.get("first", "/first").addSuccess(ExampleResponseDto)) // *protected by api key*
.middlewareEndpoints(AuthenticationApiKey)
.add(HttpApiEndpoint.get("second", "/second").addSuccess(ExampleResponseDto)) // protected by oauth2
.middlewareEndpoints(AuthenticationOauth2)
.add(HttpApiEndpoint.get("third", "/third").addSuccess(ExampleResponseDto)); // not protected I'm fine with closing the issue, however a line in the doc regarding this behavior could help others |
The first endpoint will be protected by both. It will hit oauth first, and then the API key middleware. |
okayy that makes sense, thank you for the explanation |
What version of Effect is running?
3.12.11
What steps can reproduce the bug?
with the following api definition
the endpoint
/first
is protected by.middlewareEndpoints(AuthenticationOauth2)
when I am expecting it to be behind.middlewareEndpoints(AuthenticationApiKey)
What is the expected behavior?
When I visit
http://localhost:4242/first
I should getUnauthorizedApiKey
errorWhat do you see instead?
I get the error
UnauthorizedOauth2
Additional information
a full code example
I'm using
and the code to call the api:
The text was updated successfully, but these errors were encountered: