38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
// Follow this setup guide to integrate the Deno language server with your editor:
|
|||
|
|
// https://deno.land/manual/getting_started/setup_your_environment
|
||
|
|
// This enables autocomplete, go to definition, etc.
|
||
|
|
|
||
|
|
// Setup type definitions for built-in Supabase Runtime APIs
|
||
|
|
import "@supabase/functions-js/edge-runtime.d.ts"
|
||
|
|
import { withSupabase } from "@supabase/server"
|
||
|
|
|
||
|
|
// Logs are visible from 'functions' container inspector
|
||
|
|
console.log("Hello from Functions!");
|
||
|
|
|
||
|
|
// This endpoint uses 'publishable' | 'secret' access, apiKey is required.
|
||
|
|
// Use publishable for Client-facing, key-validated endpoints
|
||
|
|
// Use secret for Server-to-server, internal calls
|
||
|
|
export default {
|
||
|
|
fetch: withSupabase({ auth: ["publishable", "secret"] }, async (req, ctx) => {
|
||
|
|
// Called by another service with a secret key
|
||
|
|
// ctx.supabaseAdmin bypasses RLS — use for privileged operations
|
||
|
|
/*
|
||
|
|
if (ctx.authMode === "secret") {
|
||
|
|
const { user_id } = await req.json();
|
||
|
|
const { data } = await ctx.supabaseAdmin.auth.admin.getUserById(user_id);
|
||
|
|
|
||
|
|
return Response.json({
|
||
|
|
email: data?.user?.email,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
|
||
|
|
return Response.json({ message: "Hello from Edge Functions!" });
|
||
|
|
}),
|
||
|
|
};
|
||
|
|
|
||
|
|
// To invoke:
|
||
|
|
// curl 'http://localhost:<API_GW_HTTP_PORT>/functions/v1/hello' \
|
||
|
|
// --header 'apiKey: <sb_publishable/sb_secret key>'
|
||
|
|
|