Enforces PKCE-based OAuth code flow replacing implicit auth flows for modern Supabase auth.
100
100%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Enforces PKCE-based OAuth code flow replacing implicit auth flows for modern Supabase auth.
This tile implements Proof Key for Code Exchange (PKCE) as the mandatory auth flow for Supabase projects using modern SSR frameworks. PKCE replaces the implicit flow (token-in-fragment) with a secure code exchange performed server-side. Tokens are synchronized via secure HTTP-only cookies, eliminating exposure through localStorage or URL fragments.
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(url, anonKey, {
auth: { flowType: 'pkce' }
});// app/auth/callback/route.ts
import { createServerClient } from '@supabase/ssr';
import { NextResponse } from 'next/server';
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const code = searchParams.get('code');
if (code) {
const supabase = createServerClient(/* cookie config */);
await supabase.auth.exchangeCodeForSession(code);
}
return NextResponse.redirect(new URL('/', request.url));
}// middleware.ts
const supabase = createServerClient(/* cookie config */);
await supabase.auth.getUser(); // refreshes session via cookiessupabase/implicit-auth-flow.supabase-mcp-verification. All downstream auth consumers MUST use PKCE-issued sessions.