Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

implement authorization check locally

Jean-Baptiste Kaiser5263bd939f42
diff --git a/makefile b/makefile
index 6e615313..d8b861a4 100644
--- a/makefile
+++ b/makefile
@@ -10,7 +10,7 @@ start-supabase: ## start supabase locally
npx supabase start
start-supabase-functions: ## start the supabase Functions watcher
- npx supabase functions serve
+ npx supabase functions serve --env-file supabase/functions/.env.development
start-app: ## start the app locally
npm run dev
diff --git a/supabase/functions/.env.development b/supabase/functions/.env.development
new file mode 100644
index 00000000..de091bc8
--- /dev/null
+++ b/supabase/functions/.env.development
@@ -0,0 +1,2 @@
+POSTMARK_WEBHOOK_USER=testuser
+POSTMARK_WEBHOOK_PASSWORD=testpwd
diff --git a/supabase/functions/postmark/index.ts b/supabase/functions/postmark/index.ts
index 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 requests
if (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();