diff --git a/examples/edge-functions/app/package.json b/examples/edge-functions/app/package.json index 810ef0f15e6..d942f3411bd 100644 --- a/examples/edge-functions/app/package.json +++ b/examples/edge-functions/app/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { - "@supabase/supabase-js": "^1.33.3", - "@supabase/ui": "^0.36.4", + "@supabase/auth-ui-react": "^0.2.1", + "@supabase/supabase-js": "^2.0.0-rc.12", "@testing-library/jest-dom": "^5.16.3", "@testing-library/react": "^12.1.4", "@testing-library/user-event": "^13.5.0", diff --git a/examples/edge-functions/app/src/App.js b/examples/edge-functions/app/src/App.js index f08f60348e8..89f57cfe09d 100644 --- a/examples/edge-functions/app/src/App.js +++ b/examples/edge-functions/app/src/App.js @@ -1,11 +1,10 @@ import React, { useState } from 'react' -import { Auth, Button, Typography, Select } from '@supabase/ui' +import { Auth, ThemeSupa } from '@supabase/auth-ui-react' import JSONInput from 'react-json-editor-ajrm' import locale from 'react-json-editor-ajrm/locale/en' import { supabase } from './utils/supabaseClient' import { functionsList } from './functionsList' -const { Title, Text } = Typography const sampleObject = { name: 'world' } function App() { @@ -25,29 +24,40 @@ function App() { return (
- - Supabase Egde Functions Test Client - +

Supabase Egde Functions Test Client

- - Request - - Function - setSupaFunction(e.target.value)} + > {functionsList.map((func) => ( - + + ))} - - + +

Note: when using locally, this selection doesn't have any effect and the function that's currently being served via the CLI is called instead. - - - Body - +

+

Body

setRequestJson(jsObject)} placeholder={sampleObject} @@ -55,27 +65,31 @@ function App() { height="100" width="100%" /> - +
- - Response - -
{JSON.stringify(responseJson, null, 2)}
+

Response

+
{JSON.stringify(responseJson, null, 2)}
- - Log in to see RLS in action - +

Log in to see RLS in action

{user ? (
- {`Logged in as ${user.email}`} - +

{`Logged in as ${user.email}`}

+
) : ( - + )}
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, })