Next.js Discord

Discord Forum

Is there an explainer about how to add "request scope" objects in NextJS middleware?

Unanswered
American Shorthair posted this in #help-forum
Open in Discord
Avatar
American ShorthairOP
There's a lot of express middleware examples out there where you get some (possibly expensive to acquire) object (often from your database) and then stick it in the request. As near as the docs and LLMs can tell me that won't work in the edge runtime router so you're back to jamming things into the headers like it's 1993.

What's the "right" way to do something like "use an auth header to lookup a thing in the DB and then make it available globally for the lifetime of the request" in an app router app? Or a doc/article/unit test that helped you to understand it? Particularly I'd like this to work in server actions and components.

0 Replies