# Remix + Supabase: the client lives and dies with the request

Every Remix loader and action receives the request, and that is where the Supabase client belongs. The two failure modes are a module-level client shared across requests, and a client whose refreshed cookies are never written back to the response.

## Checkable procedure

1. Write a `getSupabaseClient(request)` helper that builds `createServerClient` from `@supabase/ssr` per call, with cookies read from the request's `Cookie` header.
2. After any auth operation in an action (sign in, sign out, refresh), write the client's updated cookies onto the redirect/response you return. If you return a fresh `redirect()` without copying the `setAll` cookies, the browser never stores the new session and the user bounces back to login.
3. In loaders, verify with `auth.getClaims()` before returning user-scoped data. A loader that trusts a user id from the URL instead of the session is an IDOR waiting to happen.
4. Client-side components use `createBrowserClient`. Do not pass the server client into the browser via loader data, it carries no usable session there and confuses the next agent.
5. Supabase Auth UI or custom forms both work, but the session must end up in cookies for loaders to see it. Token-in-localStorage alone is invisible to loaders.

## Quick test

Sign in through an action, then immediately load a protected route. If the protected loader sees you as logged out, the action did not write cookies back onto its response.