docs: add React Router middleware example - #274
Conversation
7cbc932 to
cbb7265
Compare
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
cbb7265 to
e86941b
Compare
|
@claude can you do a first pass review of this PR? |
mandarini
left a comment
There was a problem hiding this comment.
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.
|
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. |
Summary
Test plan
npm test(102/102 passed)