Skip to content

fix: middleware state reset between middlewares#1500

Merged
marvinhagemeister merged 3 commits into
mainfrom
middleware-state
Jul 24, 2023
Merged

fix: middleware state reset between middlewares#1500
marvinhagemeister merged 3 commits into
mainfrom
middleware-state

Conversation

@marvinhagemeister

Copy link
Copy Markdown
Contributor

Fixes #1497 .

@deer deer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely fix! I'm surprised there weren't tests for this already.

Perhaps you should add a small note in the documentation? Right after The `ctx` also has a `state` property that can be used to pass arbitrary data to downstream (or upstream) handlers. you could add:
`State` is normally set by modifying its properties, e.g. `ctx.state.loggedIn = true`, but you can also modify the entire object like `ctx.state = { loggedIn = true }`. (Or something like that. Just to let people know that both options are available.)

Comment thread tests/main_test.ts

@iuioiua iuioiua left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread docs/concepts/middleware.md Outdated
@marvinhagemeister marvinhagemeister merged commit 38d4b90 into main Jul 24, 2023
@marvinhagemeister marvinhagemeister deleted the middleware-state branch July 24, 2023 09: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.

ctx.state is reset between middlewares

3 participants