Skip to content

[#78] jwtMiddleware throws at startup#486

Merged
rido-min merged 4 commits intomainfrom
southworks/fix/jwt-middleware-error
Jul 23, 2025
Merged

[#78] jwtMiddleware throws at startup#486
rido-min merged 4 commits intomainfrom
southworks/fix/jwt-middleware-error

Conversation

@ceciliaavila
Copy link
Copy Markdown
Collaborator

Fixes #78

Description

This PR fixes the error thrown by the jwtMiddleware when trying to get the authorization header from a request that does not include it. It adds a validation to return 405 Method not allowed responsense when the request is neither POST nor GET.
It also adds a new unit test to cover this case.

Detailed Changes

  • Updated jwt-middleware to:
    • Include the new method validation.
    • Set the failed flag to true when it can't retrieve the authorization header. This will prevent the execution to continue after sending the response and the Cannot set headers after they are sent to the client error.
  • Added a unit test in jwt-middleware.test and update the existing ones to assert the next function not being called.

Testing

The images illustrate the handling of an OPTIONS method request before the changes and the improvements implemented after the fix.
image

Comment thread packages/agents-hosting/src/auth/jwt-middleware.ts Outdated
@rido-min rido-min enabled auto-merge (squash) July 23, 2025 20:02
@rido-min rido-min merged commit 8fe61ba into main Jul 23, 2025
7 checks passed
@rido-min rido-min deleted the southworks/fix/jwt-middleware-error branch July 23, 2025 20:03
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

Successfully merging this pull request may close these issues.

jwtMiddleware throws at startup

2 participants