🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

Unlocking User Data: Building a Secure Supabase Edge Function

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In this tutorial, we'll delve into the world of Supabase Edge Functions. We'll explore how to set up a local development environment and build a simple function to list all users within your Supabase project. This hands-on guide will empower you to leverage the full potential of Supabase Edge Functions for your next project.









Prerequisites



Assuming you have your local Supabase CLI setup and linked to your remote project.



Make sure Supabase is running with:




CODE
supabase start









Creating a New Edge Function



Run this to create a new edge function named 'admin-list-all-users':




CODE
supabase functions new admin-list-all-users






This creates a new folder under ./supabase named 'admin-list-all-users' and inside that folder is an index.ts file.






Running Functions Locally



To run functions locally using the CLI, execute this command. Note that this ties up a console window until it is stopped with control + c. While it is running, you can see information about the function calls, and even more if you run it with the --debug flag.




CODE
supabase functions serve






Before you edit the function, it would be a good idea to run the demo "hello world" code to make sure the basics are working. This code should be in your newly created function already but here it is just in case.






Demo Code






CODE
// Setup type definitions for built-in Supabase Runtime APIs
import 'jsr:@supabase/functions-js/edge-runtime.d.ts';

console.log('Hello from Functions!');

Deno.serve(async (req) => {
const { name } = await req.json();
const data = {
message: `Hello ${name}!`
};

return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } });
});









Running Your Function Locally



There is also a curl command at the bottom of your index.ts file that looks like this:




CODE
curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/admin-list-all-users' \
--header 'Authorization: Bearer SUPABASE_ANON_KEY_HERE' \
--header 'Content-Type: application/json' \
--data '{"name":"World"}'






Your SUPABASE_ANON_KEY should be automatically populated with the correct key for your local setup. Copy and paste that to your terminal and run it.



You should see a response like this:




CODE
{"message":"Hello World!"}%









The Fun Part



Now lets replace the demo code with this:




CODE
// Setup type definitions for built-in Supabase Runtime APIs
import 'jsr:@supabase/functions-js/edge-runtime.d.ts';

// Import necessary modules with full URLs
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';

// Access environment variables for Supabase URL and Service Role Key
const supabaseUrl = Deno.env.get('SUPABASE_URL')!;
const serviceRoleKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!;

// Initialize the Supabase client with the service role key
const supabase = createClient(supabaseUrl, serviceRoleKey);

serve(async (_req) => {
try {
// Fetch all users
const { data, error } = await supabase.auth.admin.listUsers();

if (error) throw error;

// Return the list of users as JSON
return new Response(JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
status: 200
});
} catch (error: any) {
// Handle errors and return a JSON response
return new Response(JSON.stringify({ error: error.message }), {
headers: { 'Content-Type': 'application/json' },
status: 500
});
}
});






This will automatically pull your Supabase URL and service role key then return a JSON object containing all users.



Again, run the function locally like this. Notice that we do not need to pass any data to the function this time.




CODE
curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/admin-list-all-users' \
--header 'Authorization: Bearer SUPABASE_ANON_KEY_HERE' \
--header 'Content-Type: application/json'









Conclusion



By following these steps, you've successfully created and tested a Supabase Edge Function locally that can securely access and pass user data to the client. This powerful ability enables you to extend your Supabase application's capabilities without the need for complex server setups.



Take the next steps and deploy this to run it agains your linked (live) Supabase project. Explore the vast possibilities of Edge Functions and leverage them to create secure, innovative and efficient applications by reading the Supabase docs.



Supabase Edge Functions DOCS

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Unlocking User Data: Building a Secure Supabase Edge Function

Thematisch verwandte Begriffe: Unlocking, User, Data, Building · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...