Configures server-side session synchronization via secure HTTP-only cookies for SSR frameworks.
94
94%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Configures server-side session synchronization via secure HTTP-only cookies for SSR frameworks.
This tile implements auth session management where the server owns the session lifecycle. Auth tokens are stored in HTTP-only cookies, preventing client-side JavaScript access. Middleware intercepts every request to validate the session via getUser(), refresh tokens when needed, and propagate updated cookies in the response. The PKCE flow MUST be the authentication method -- implicit flow is incompatible.
import { createServerClient } from '@supabase/ssr';
const supabase = createServerClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
cookies: {
getAll: () => cookieStore.getAll(),
setAll: (cookiesToSet) => {
cookiesToSet.forEach(({ name, value, options }) => {
cookieStore.set(name, value, { ...options, httpOnly: true, secure: true });
});
},
},
});| Method | Verifies JWT | Safe for Server Auth |
|---|---|---|
getSession() | No | No |
getUser() | Yes | Yes |
| Option | Value | Rationale |
|---|---|---|
| httpOnly | true | Prevents XSS token theft |
| secure | true | HTTPS-only transmission |
| sameSite | lax | CSRF protection |
| path | / | Available to all routes |
pkce-auth-flow is configured.