import { withOAuthProtectedResource, withSupabase } from '@supabase/server'
Deno.serve(
withOAuthProtectedResource(
withSupabase({ auth: 'user' }, async (_req, { supabase }) => {
const { data, error } = await supabase.from('items').select('*')
if (error) throw error
return Response.json(data)
}),
),
)
Wraps a request handler with OAuth 2.1 Protected Resource behavior (RFC 9728) for Supabase Edge Functions.
GET /{fn}/oauth-protected-resource(with permissive CORS, including theOPTIONSpreflight, so browser-based clients can read it)401from the inner handler withWWW-Authenticate: Bearer resource_metadata="...", unless the handler already set aWWW-Authenticateheader (its value wins)404for any other path (Edge Functions are single-endpoint - the inner handler owns/{fn}only)The returned handler's optional second parameter is the host's platform argument (a Workers
env, a DenoServeHandlerInfo) and is forwarded to the inner handler unchanged — required forwithSupabaseto capture it.