Policies sudah ada di Supabase:
- ✅ Authenticated users can upload EPUBs
- ✅ Authenticated users can read EPUBs
- ✅ Authenticated users can update EPUBs
- ✅ Authenticated users can delete EPUBs
❌ Error: Upload failed: new row violates row-level security policy
Penyebab: Migration script menggunakan anon key yang tidak authenticated. Policies Anda require authenticated users only.
- Buka Supabase Dashboard → Settings → API
- Scroll ke bagian Project API keys
- Copy
service_rolekey (BUKAN anon key!)- Klik icon "eye" untuk show key
- Klik icon "copy"
Edit file .env.migration:
# .env.migration
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
# Paste service_role key yang Anda copy dari Step 1Ganti:
your-project.supabase.codengan URL project AndaeyJhbG...dengan service_role key yang Anda copy
cd /Users/ridhoizzulhaq/llibere-main
# Migrate all books (recommended)
/opt/homebrew/bin/node scripts/migrate-with-service-key.mjs
# Or migrate specific book (contoh: book ID 1761747515)
/opt/homebrew/bin/node scripts/migrate-with-service-key.mjs 1761747515Expected output:
🔑 Using SERVICE ROLE key (bypasses RLS policies)
📚 Fetching all books from database...
Found 4 books total
- IPFS (needs migration): 4
- Already migrated: 0
📖 Migrating Book ID: 1761747515
Title: Around the World in Eighty Days
📥 Downloading from IPFS...
✅ Downloaded 0.42 MB
📤 Uploading to Supabase Storage...
✅ Uploaded to: libere-books/1761747515/book.epub
💾 Updating database...
✅ Database updated
🎉 Migration completed!
[... 3 more books ...]
============================================================
📊 MIGRATION SUMMARY
============================================================
✅ Successful: 4
❌ Failed: 0
============================================================
⚠️ REMINDER: Delete .env.migration after migration!
- Storage → libere-books
- Harusnya ada folder dengan ID books:
📁 1761747515/ 📄 book.epub 📁 1761866400/ 📄 book.epub 📁 1761866611/ 📄 book.epub 📁 1761866872/ 📄 book.epub
npm run dev- Login ke app
- Buka bookshelf
- Click "Read Now" pada salah satu book
- Book harusnya load dari Supabase Storage!
.env.migration setelah migration selesai!
rm /Users/ridhoizzulhaq/llibere-main/.env.migrationService role key adalah admin key dan tidak boleh disimpan di project!
Policies Anda sudah aman (authenticated users only):
- ✅ Only authenticated users can upload
- ✅ Only authenticated users can read
- ✅ Only authenticated users can update
- ✅ Only authenticated users can delete
Tidak perlu ganti policies! 👍
- Bucket
libere-bookssudah dibuat ✅ - Bucket setting: Private ✅
- Storage policies sudah ada (authenticated only) ✅
- Service role key didapatkan dari dashboard
-
.env.migrationfile sudah diisi - Migration script berhasil
- Files ada di Storage dashboard
- Web app bisa baca books
-
.env.migrationfile sudah didelete
Solusi: Buat bucket dulu di Storage → New bucket → Name: libere-books → UNCHECK Public
Solusi: Policy sudah ada, skip step 2
Penyebab: Policies sudah di-drop
Solusi: Run secure policies (authenticated only) dari Step 6
Books di database Anda:
- Total: 4 books
- Need migration: 4 books (semuanya dari IPFS)
- File sizes:
- Around the World in Eighty Days: 0.42 MB
- Alice's Adventures in Wonderland: 0.18 MB
- Frankenstein: 0.45 MB
- Beowulf: 0.38 MB
Total download: ~1.43 MB (cepat!)
Jalankan Step 1-6 di atas, dan books Anda akan ter-migrate ke Supabase Storage!