Start + Clerk + Supabase

I've ran out of hair to pull so am hoping someone can clarify how to use Supabase clients in a loader given I'm using latest Clerk as Auth provider instead of Supabase Auth. The loader is isomorphic but the clerk / superbase docs imply the clerk token is obtained differently for the supabase client on the client and the supabase client on the server. We can't use clerks Auth helper hooks in the loaders either so currently I'm extracting the clerk Auth token in the _root.tsx beforeLoad and then adding it to the context. Then in my authed routes I'm extracting it from the context and passing it into a createSupabaseClient function which then returns it in the accessToken method. This appears to work but it all seems a bit convoluted and, well, a bit of a code smell.
I feel i'm missing something, something conceptual perhaps. I would have thought that middleware would handle all this and I have Clerk Middleware set up and documented but it doesn't seem to do much.
I've trawled the Clerk and Supabase examples but there isn't one that uses both.
So, can anyone give my head a nudge in the right direction....or should I just stick it in a guillotine.
Was this page helpful?