From 48397917a9dcb8caf2b799e5b86a7d07a1194c4a Mon Sep 17 00:00:00 2001 From: Aymeric Rabot Date: Thu, 19 Feb 2026 01:41:48 -0500 Subject: [PATCH] feat: auto-create avatars storage bucket on server startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses Next.js instrumentation.ts to ensure the Supabase "avatars" bucket exists on first boot — no manual setup needed. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/editor/instrumentation.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 apps/editor/instrumentation.ts diff --git a/apps/editor/instrumentation.ts b/apps/editor/instrumentation.ts new file mode 100644 index 00000000..47f2b8cf --- /dev/null +++ b/apps/editor/instrumentation.ts @@ -0,0 +1,24 @@ +export async function register() { + // Only run on the server + if (process.env.NEXT_RUNTIME === 'nodejs') { + const { createClient } = await import('@supabase/supabase-js') + + const url = process.env.NEXT_PUBLIC_SUPABASE_URL + const key = process.env.SUPABASE_SERVICE_ROLE_KEY + if (!url || !key) return + + const supabase = createClient(url, key) + + const { data: buckets } = await supabase.storage.listBuckets() + const exists = buckets?.some((b) => b.name === 'avatars') + + if (!exists) { + await supabase.storage.createBucket('avatars', { + public: true, + fileSizeLimit: 5 * 1024 * 1024, // 5MB + allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/gif'], + }) + console.log('Created "avatars" storage bucket') + } + } +}