How do i protect a Cloudflare Worker route to authorize only if the user is authenticated on Supabase?
I'm using Cloudflare Pages Function to create a worker inside the Cloudflare Pages: https://developers.cloudflare.com/pages/platform/functions/
import { createClient } from '@supabase/supabase-js'
export async function onRequest(context) {
const token = context.request.headers.get('Cookie')
const supabase = createClient(
'url',
'key')
const {user, error} = await supabase.auth.getUser(token)
if(user){
return new Response("YES!")
} else {
return new Response("Access Denied")
}
}