Correct auth.mdx examples (#34746)

This commit is contained in:
Kevin Kuhl authored and GitHub committed 2025-06-12 20:55:24 +00:00
1 parent 87b04cc255
commit 82715efc25
2 files changed
+8 -4

No files matched your search

@@ -62,7 +62,7 @@ At it's most basic a function has the following parts:
<Admonition type="caution">
When naming your functions, please make the name of the function unique as overloaded functions are not supported.
When naming your functions, make the name of the function unique as overloaded functions are not supported.
</Admonition>
+7 -3
View File
@@ -19,9 +19,11 @@ Deno.serve(async (req: Request) => {
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
// Create client with Auth context of the user that called the function.
// This way your row-level-security (RLS) policies are applied.
{
global: {
headers: { Authorization: req.headers.get('Authorization') },
headers: { Authorization: req.headers.get('Authorization')! },
},
}
);
@@ -38,7 +40,7 @@ Importantly, this is done _inside_ the `Deno.serve()` callback argument, so that
## Fetching the user
After initializing a Supabase client with the Auth context, you can use `getUser()` to fetch the user object, and run queries in the context of the user with [Row Level Security (RLS)](/docs/guides/database/postgres/row-level-security) policies enforced.
By getting the JWT from the `Authorization` header, you can provide the token to `getUser()` to fetch the user object to obtain metadata for the logged in user.
```js
import { createClient } from 'npm:@supabase/supabase-js@2'
@@ -81,9 +83,11 @@ Deno.serve(async (req: Request) => {
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
// Create client with Auth context of the user that called the function.
// This way your row-level-security (RLS) policies are applied.
{
global: {
headers: { Authorization: req.headers.get('Authorization') },
headers: { Authorization: req.headers.get('Authorization')! },
},
}
);