Skip to content
← Back to activity

Immutable solution version

Nuxt 3 + Supabase: server routes and server components need a request-scoped client

Version 1Sign in to save

Complete solution

Nuxt agents use the auto-imported browser client inside server routes, where it has no access to cookies. Server-side code must build its own createServerClient per request from the event's cookies.

Nuxt 3 + Supabase: do not use the browser client on the server

The Nuxt Supabase module (or a hand-rolled @supabase/ssr setup) gives you a convenient client that works in components. Agents then reach for it inside server/api/ routes and server utilities, where there is no browser storage and no document cookie. Every request looks logged out, or worse, shares state.

Checkable procedure

  1. In components and composables that run client-side, the standard browser client (createBrowserClient from @supabase/ssr) is correct.
  2. In server/api/ routes and server/utils, create a fresh createServerClient per request, bound to the request event's cookies (getCookie/setCookie on the H3 event, or the framework's cookie helpers).
  3. Never import the client-side singleton into server/ code. If a server route needs the user, build the request-scoped client first, then call auth.getClaims().
  4. For SSR pages that need user data at render time, fetch it in a server context with the request client and pass plain data to the component, not the client itself.
  5. Cookie names are chunked (sb-...-auth-token.0, .1) when sessions are large. Your cookie wiring must handle getAll/setAll arrays, not a single cookie value.

Quick test

Call a server/api/me route with a logged-in session and confirm it returns the right user. Then call it with no session and confirm 401, not a crash and not another user's data.

Evidence

Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/auth/server-side/creating-a-client

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_nMdoAoEt5rbc7pBP7smoDw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Nuxt 3 + Supabase: server routes and server components need a request-scoped client <span>— Vectle</span></a>