- {`Logged in as ${user.email}`}
- supabase.auth.signOut()}>Sign out
+
{`Logged in as ${user.email}`}
+ supabase.auth.signOut()}
+ >
+ Sign out
+
) : (
-
+
)}
diff --git a/examples/edge-functions/app/src/index.js b/examples/edge-functions/app/src/index.js
index 3a641dd416d..36515be3349 100644
--- a/examples/edge-functions/app/src/index.js
+++ b/examples/edge-functions/app/src/index.js
@@ -2,7 +2,7 @@ import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
-import { Auth } from '@supabase/ui'
+import { Auth } from '@supabase/auth-ui-react'
import { supabase } from './utils/supabaseClient'
ReactDOM.render(
diff --git a/examples/edge-functions/supabase/functions/_shared/supabaseClient.ts b/examples/edge-functions/supabase/functions/_shared/supabaseClient.ts
deleted file mode 100644
index 2205294d529..00000000000
--- a/examples/edge-functions/supabase/functions/_shared/supabaseClient.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { createClient } from 'https://esm.sh/@supabase/supabase-js@^1.33.2'
-
-export const supabaseClient = createClient(
- // Supabase API URL - env var exported by default when deployed.
- Deno.env.get('SUPABASE_URL') ?? '',
- // Supabase API ANON KEY - env var exported by default when deployed.
- Deno.env.get('SUPABASE_ANON_KEY') ?? ''
-)
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.ts
index a1103cc5489..d5a54885801 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
@@ -3,7 +3,7 @@
// This enables autocomplete, go to definition, etc.
import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
-import { supabaseClient } from '../_shared/supabaseClient.ts'
+import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.0.0-rc.12'
import { corsHeaders } from '../_shared/cors.ts'
console.log(`Function "select-from-table-with-auth-rls" up and running!`)
@@ -15,14 +15,26 @@ serve(async (req: Request) => {
}
try {
- // Set the Auth context of the user that called the function.
- // This way your row-level-security (RLS) policies are applied.
- supabaseClient.auth.setAuth(req.headers.get('Authorization')!.replace('Bearer ', ''))
+ // Create a Supabase client with the Auth context of the logged in user.
+ const supabaseClient = createClient(
+ // Supabase API URL - env var exported by default.
+ Deno.env.get('SUPABASE_URL') ?? '',
+ // Supabase API ANON KEY - env var exported by default.
+ 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')! } } }
+ )
+ // Now we can get the session or user object
+ const {
+ data: { user },
+ } = await supabaseClient.auth.getUser()
+ // And we can run queries in the context of our authenticated user
const { data, error } = await supabaseClient.from('users').select('*')
- console.log({ data, error })
+ if (error) throw error
- return new Response(JSON.stringify({ data, error }), {
+ return new Response(JSON.stringify({ user, data }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
})