Skip to content

docs: add React Router middleware example - #274

Merged
mandarini merged 2 commits into
supabase:mainfrom
sornapudisuresh:docs/149-react-router-middleware-example
Jul 29, 2026
Merged

docs: add React Router middleware example#274
mandarini merged 2 commits into
supabase:mainfrom
sornapudisuresh:docs/149-react-router-middleware-example

Conversation

@sornapudisuresh

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • npm test (102/102 passed)
  • Docs read-through against current React Router middleware APIs

@sornapudisuresh
sornapudisuresh requested review from a team as code owners July 27, 2026 17:18
@sornapudisuresh
sornapudisuresh force-pushed the docs/149-react-router-middleware-example branch from 7cbc932 to cbb7265 Compare July 27, 2026 18:18
Show how to create a server client in stable React Router middleware,
refresh the session with getClaims(), and write Set-Cookie headers on
the response.

Fixes supabase#149
@sornapudisuresh
sornapudisuresh force-pushed the docs/149-react-router-middleware-example branch from cbb7265 to e86941b Compare July 28, 2026 08:55
@mandarini

Copy link
Copy Markdown
Contributor

@claude can you do a first pass review of this PR?

@mandarini mandarini 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.

Hi @sornapudisuresh, thank you so much for contributing to Supabase! 💚

This is a great addition! One thing to fix before merging: I tried compiling the supabaseMiddleware snippet against react-router@8.3.0, and the hand-written context type doesn't match React Router's actual type:

context: { set: (key: unknown, value: unknown) => void };

RouterContextProvider.set is actually a generic method keyed on typed Context objects, so assigning supabaseMiddleware to Route.MiddlewareFunction[] (as the home.tsx snippet does) fails to type-check. Could you drop the inline context type and let it be inferred from Route.MiddlewareFunction/Route.args instead? That should resolve it and keep the example copy-pasteable.

Thanks again for taking the time to put this together, contributions like yours are what keep these docs useful for everyone.

Infer middleware arguments from React Router's MiddlewareFunction type
so the example type-checks with RouterContextProvider.

Addresses review feedback on supabase#274.
@sornapudisuresh

Copy link
Copy Markdown
Contributor Author

Thanks @mandarini! Fixed in the latest commit. The middleware now uses React Router’s MiddlewareFunction so request, context, and next are inferred from the framework’s actual types. Prettier passes and all 102 tests pass.

@mandarini
mandarini merged commit 69a6209 into supabase:main Jul 29, 2026
3 checks passed
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.

Add example for using with React Router middleware

2 participants