A full-featured CRM built with React, shadcn/ui, and Supabase.
implement authorization check locally
Jean-Baptiste Kaiser5263bd939f42
diff --git a/makefile b/makefileindex 6e615313..d8b861a4 100644--- a/makefile+++ b/makefile@@ -10,7 +10,7 @@ start-supabase: ## start supabase locallynpx supabase startstart-supabase-functions: ## start the supabase Functions watcher- npx supabase functions serve+ npx supabase functions serve --env-file supabase/functions/.env.developmentstart-app: ## start the app locallynpm run devdiff --git a/supabase/functions/.env.development b/supabase/functions/.env.developmentnew file mode 100644index 00000000..de091bc8--- /dev/null+++ b/supabase/functions/.env.development@@ -0,0 +1,2 @@+POSTMARK_WEBHOOK_USER=testuser+POSTMARK_WEBHOOK_PASSWORD=testpwddiff --git a/supabase/functions/postmark/index.ts b/supabase/functions/postmark/index.tsindex a80ada12..9291dc3f 100644--- a/supabase/functions/postmark/index.ts+++ b/supabase/functions/postmark/index.ts@@ -6,12 +6,27 @@import 'jsr:@supabase/functions-js/edge-runtime.d.ts';import { supabaseAdmin } from '../_shared/supabaseAdmin.ts';+const webhookUser = Deno.env.get('POSTMARK_WEBHOOK_USER');+const webhookPassword = Deno.env.get('POSTMARK_WEBHOOK_PASSWORD');+if (!webhookUser || !webhookPassword) {+ throw new Error(+ 'Missing POSTMARK_WEBHOOK_USER or POSTMARK_WEBHOOK_PASSWORD'+ );+}+const expectedAuthorization = `Basic ${btoa(`${webhookUser}:${webhookPassword}`)}`;+Deno.serve(async req => {// Only allow POST requestsif (req.method !== 'POST') {return new Response(null, { status: 405 });}+ // Check the Authorization header+ const authorization = req.headers.get('Authorization');+ if (authorization !== expectedAuthorization) {+ return new Response('Unauthorized', { status: 403 });+ }+const { ToFull, FromFull, Subject, TextBody, StrippedTextReply } =await req.json();