[WIP] 20771/fix auth get user for edge functions (#23155)

* docs: fix RPC sql example

* docs: fix auth.getUser() calls to use auth.getUser(jwt)

- add lines to get token before calling auth.getUser() as session is not
set after setting authHeader in client

* Apply suggestions from code review

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
This commit is contained in:
Simon HaandCharis authored and GitHub committed 2024-04-30 20:34:58 +00:00
1 parent cc09ae54a5
commit 597c554e7a
3 files changed
+12 -4

No files matched your search

@@ -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 object
const {
data: { user },
} = await supabaseClient.auth.getUser()
} = await supabaseClient.auth.getUser(token)
// And we can run queries in the context of our authenticated user
const { data, error } = await supabaseClient.from('users').select('*')
@@ -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 object
const {
data: { user },
} = await supabaseClient.auth.getUser()
} = await supabaseClient.auth.getUser(token)
if (!user) throw new Error('no user')
console.log(user.id)