A full-featured CRM built with React, shadcn/ui, and Supabase.
code review
Jean-Baptiste Kaiser9af9ad3a71b6
diff --git a/doc/src/content/docs/developers/supabase-configuration.mdx b/doc/src/content/docs/developers/supabase-configuration.mdxindex 3cb0dc92..29c47e6e 100644--- a/doc/src/content/docs/developers/supabase-configuration.mdx+++ b/doc/src/content/docs/developers/supabase-configuration.mdx@@ -13,7 +13,7 @@ Atomic CRM comes with a CLI utility to create a backend instance on [supabase.comake supabase-remote-init```-The script will ask you for the Supabase instance name, create the database, apply the migrations, and set up the secrets needed by the edge functions. Finally, it will create a `.env.production.local` file with your remote Supabase configuration.+The script will ask you for the Supabase instance name, create the database, apply the migrations and deploy the edge functions. Finally, it will create a `.env.production.local` file with your remote Supabase configuration.The script cannot yet automate the configuration of the required SMTP provider on your Supabase instance. To do that, please follow the instructions detailed in the [Email Provider Setup](#email-provider-setup) section.@@ -33,10 +33,10 @@ Now, link the local project to the Supabase instance. You'll be asked to enter tnpx supabase link --project-ref ********************```-Set up secrets for the Supabase instance (follow this [guide](https://supabase.com/docs/guides/api/api-keys#where-to-find-keys) to find your publishable and secret keys):+Set up secrets for the Supabase instance (follow this [guide](https://supabase.com/docs/guides/api/api-keys#where-to-find-keys) to find your publishable key):```sh-npx supabase secrets set SB_PUBLISHABLE_KEY=<publishable_key> SB_SECRET_KEY=<secret_key>+npx supabase secrets set SB_PUBLISHABLE_KEY=<publishable_key>```Then, apply the migrations and deploy the edge functions:diff --git a/scripts/supabase-remote-init.mjs b/scripts/supabase-remote-init.mjsindex 2a151be2..2c845bfc 100644--- a/scripts/supabase-remote-init.mjs+++ b/scripts/supabase-remote-init.mjs@@ -17,7 +17,7 @@ import fs from "node:fs";await waitForProjectToBeReady({ projectRef });// This also ensures the project is ready- const { publishableKey, secretKey } = await fetchApiKeys({+ const { publishableKey } = await fetchApiKeys({projectRef,});@@ -33,7 +33,6 @@ import fs from "node:fs";await setupSupabaseSecrets({projectRef,publishableKey,- secretKey,});await persistSupabaseEnv({@@ -157,7 +156,6 @@ async function setupDatabase({ databasePassword }) {async function fetchApiKeys({ projectRef }) {let publishableKey = "";- let secretKey = "";try {const { stdout, exitCode } = await execa("npx",@@ -193,14 +191,6 @@ async function fetchApiKeys({ projectRef }) {(key) => key.type === "publishable",)?.api_key;}-- // Prioritize the default secret key, but any secret key will work.- secretKey = jsonOutput.find(- (key) => key.type === "secret" && key.name === "default",- )?.api_key;- if (!secretKey) {- secretKey = jsonOutput.find((key) => key.type === "secret")?.api_key;- }}} catch (e) {console.error("Failed to fetch API keys");@@ -208,15 +198,15 @@ async function fetchApiKeys({ projectRef }) {throw e;}- if (publishableKey === "" || secretKey === "") {+ if (publishableKey === "") {await sleep(1000);return fetchApiKeys({ projectRef });}- return { publishableKey, secretKey };+ return { publishableKey };}-async function setupSupabaseSecrets({ projectRef, publishableKey, secretKey }) {+async function setupSupabaseSecrets({ projectRef, publishableKey }) {await execa("npx",[@@ -224,7 +214,6 @@ async function setupSupabaseSecrets({ projectRef, publishableKey, secretKey }) {"secrets","set",`SB_PUBLISHABLE_KEY=${publishableKey}`,- `SB_SECRET_KEY=${secretKey}`,"--project-ref",projectRef,],diff --git a/supabase/functions/.env b/supabase/functions/.envindex c07bcf9c..fdf9ed16 100644--- a/supabase/functions/.env+++ b/supabase/functions/.env@@ -8,4 +8,3 @@ POSTMARK_WEBHOOK_AUTHORIZED_IPS=3.134.147.250,50.31.156.6,50.31.156.77,18.217.20SB_JWT_ISSUER=http://127.0.0.1:54321/auth/v1SB_PUBLISHABLE_KEY=sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH-SB_SECRET_KEY=sb_secret_N7UND0UgjKTVK-Uodkm0Hg_xSvEMPvzdiff --git a/supabase/functions/_shared/supabaseAdmin.ts b/supabase/functions/_shared/supabaseAdmin.tsindex b440e700..308edd25 100644--- a/supabase/functions/_shared/supabaseAdmin.ts+++ b/supabase/functions/_shared/supabaseAdmin.ts@@ -1,18 +1,11 @@import type { SupabaseClient } from "jsr:@supabase/supabase-js@2";import { createClient } from "jsr:@supabase/supabase-js@2";-const supabaseUrl = Deno.env.get("SUPABASE_URL") ?? "";-const supabaseServiceRoleKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? "";-const sbSecretKey = Deno.env.get("SB_SECRET_KEY") ?? "";-const adminKey = supabaseServiceRoleKey || sbSecretKey;--if (!supabaseUrl || !adminKey) {- throw new Error("Missing SUPABASE_URL or admin key");-}-export const supabaseAdmin: SupabaseClient = createClient(- supabaseUrl,- adminKey,+ Deno.env.get("SUPABASE_URL") ?? "",+ // TODO - When Supabase finally provides the project's secret key to the functions, we'll need to use it here instead of the service role key.+ // See https://supabase.com/docs/guides/functions/auth#get-api-details+ Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? "",{auth: {autoRefreshToken: false,diff --git a/supabase/migrations/20260220154000_note_attachments_webhooks.sql b/supabase/migrations/20260220154000_note_attachments_trigger.sqlsimilarity index 96%rename from supabase/migrations/20260220154000_note_attachments_webhooks.sqlrename to supabase/migrations/20260220154000_note_attachments_trigger.sqlindex c203be69..4980dc0a 100644--- a/supabase/migrations/20260220154000_note_attachments_webhooks.sql+++ b/supabase/migrations/20260220154000_note_attachments_trigger.sql@@ -7,7 +7,7 @@ BEGINEXECUTE $url_sql$-- SQL triggers cannot read Edge Function env vars directly. Resolve the-- function URL from request context, and keep a local Docker fallback.- CREATE OR REPLACE FUNCTION public.note_attachments_webhook_url()+ CREATE OR REPLACE FUNCTION public.get_note_attachments_function_url()RETURNS textLANGUAGE plpgsqlAS $function$@@ -89,7 +89,7 @@ BEGIN);PERFORM net.http_post(- url := public.note_attachments_webhook_url(),+ url := public.get_note_attachments_function_url(),body := payload,params := '{}'::jsonb,headers := jsonb_build_object(