The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
[WIP] 20771/fix auth get user for edge functions (#23155)
Simon Ha597c554e7abc
diff --git a/apps/docs/content/guides/functions/auth.mdx b/apps/docs/content/guides/functions/auth.mdxindex 609f18a46de..06f768bc8d2 100644--- a/apps/docs/content/guides/functions/auth.mdx+++ b/apps/docs/content/guides/functions/auth.mdx@@ -40,11 +40,11 @@ Deno.serve(async (req: Request) => {const supabaseClient = createClient(Deno.env.get('SUPABASE_URL') ?? '',Deno.env.get('SUPABASE_ANON_KEY') ?? '',- { global: { headers: { Authorization: req.headers.get('Authorization')! } } })// Get the session or user object- const { data } = await supabaseClient.auth.getUser()+ const token = authHeader.replace('Bearer ', '')+ const { data } = await supabaseClient.auth.getUser(token)const user = data.userreturn new Response(JSON.stringify({ user }), {diff --git a/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts b/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.tsindex 5654c97a95b..93fc185c480 100644--- a/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts+++ b/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts@@ -28,10 +28,14 @@ Deno.serve(async (req: Request) => {},})++ // First get the token from the Authorization header+ const token = req.headers.get('Authorization').replace('Bearer ', '')+// Now we can get the session or user objectconst {data: { user },- } = await supabaseClient.auth.getUser()+ } = await supabaseClient.auth.getUser(token)// And we can run queries in the context of our authenticated userconst { data, error } = await supabaseClient.from('users').select('*')diff --git a/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts b/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.tsindex cd266975080..9ecac3b9ff9 100644--- a/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts+++ b/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts@@ -20,10 +20,14 @@ Deno.serve(async (req) => {},})++ // First get the token from the Authorization header+ const token = req.headers.get('Authorization').replace('Bearer ', '')+// Now we can get the session or user objectconst {data: { user },- } = await supabaseClient.auth.getUser()+ } = await supabaseClient.auth.getUser(token)if (!user) throw new Error('no user')console.log(user.id)