Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

changed code block on edge functions page

Ollie Halliday86de3bb26c27
diff --git a/apps/www/pages/edge-functions/edge-functions.tsx b/apps/www/pages/edge-functions/edge-functions.tsx
index a1d9cd65678..c572c51526d 100644
--- a/apps/www/pages/edge-functions/edge-functions.tsx
+++ b/apps/www/pages/edge-functions/edge-functions.tsx
@@ -223,20 +223,17 @@ import { Customer } from 'types'
serve(async (req) => {
try {
- // create a supabase client
+ // create a supabase client with Auth context of the user that called the function
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
- Deno.env.get('SUPABASE_ANON_KEY') ?? ''
+ Deno.env.get('SUPABASE_ANON_KEY') ?? '',
+ { global: { headers: { Authorization: req.headers.get('Authorization')! } } }
)
// create a stripe client
const stripe = Stripe(Deno.env.get('STRIPE_SECRET_KEY'))
- // Get the authorization header from the request.
- const authHeader = req.headers.get('Authorization').replace("Bearer ","")
- // Client now respects auth policies for this user
- supabaseClient.auth.setAuth(authHeader)
- // set the user profile
- const user = supabase.auth.user()
+ // get the current logged in user
+ const {data: { user },} = supabase.auth.getUser()
// Retrieve user metadata that only the user is allowed to select
const { data, error } = await supabaseClient