Overview
Music Store uses Supabase as its backend-as-a-service platform, providing:- PostgreSQL database for product data
- Real-time subscriptions (optional)
- RESTful API auto-generated from database schema
- Row Level Security (RLS) for data access control
Supabase Client Configuration
The application uses a centralized Supabase client located atbackend/supabaseClient.js:
backend/supabaseClient.js
The client uses Vite’s
import.meta.env to access environment variables prefixed with VITE_.Setting Up Your Supabase Project
Create a Supabase Account
- Go to supabase.com
- Sign up for a free account
- Create a new project
- Choose a database password (save this securely)
- Select a region close to your users
Get Your API Credentials
After project creation, navigate to Settings > API:
- Project URL - Your unique Supabase URL (e.g.,
https://xxxxx.supabase.co) - Project API Key (anon/public) - Safe to use in client-side code
.env.local file.Create the Database Schema
Navigate to the SQL Editor in your Supabase dashboard and run:This creates the
productos table with all necessary fields for the store.Configure Row Level Security (Optional)
For read-only public access, enable RLS and add a policy:
RLS is optional for this application since products are publicly viewable. You can disable RLS for simpler development.
Configure Environment Variables
Add your Supabase credentials to See the Environment Variables guide for detailed setup.
.env.local:.env.local
Database Schema Reference
productos Table
| Column | Type | Description |
|---|---|---|
id | BIGSERIAL | Auto-incrementing primary key |
nombre | TEXT | Product name (required) |
descripcion | TEXT | Product description |
precio | NUMERIC(10,2) | Price in currency units (required) |
categoria | TEXT | Product category (e.g., “Guitarras Electricas”) |
imagen_url | TEXT | URL or path to product image |
marca | TEXT | Brand name (e.g., “Fender”, “Gibson”) |
stock | INTEGER | Available inventory count |
destacado | BOOLEAN | Whether product is featured |
created_at | TIMESTAMP | Record creation timestamp |
Using Supabase in Components
Import the client and query data:Common Queries
Fetch All Products
Fetch All Products
Filter by Category
Filter by Category
Get Featured Products
Get Featured Products
Get Single Product by ID
Get Single Product by ID
Search Products
Search Products
Troubleshooting
Error: Invalid API key
Error: Invalid API key
- Verify your
VITE_SUPABASE_KEYin.env.localmatches the dashboard - Make sure you’re using the
anon(public) key, not theservice_rolekey - Restart the dev server after changing environment variables
Error: relation 'productos' does not exist
Error: relation 'productos' does not exist
- Run the CREATE TABLE SQL in the Supabase SQL Editor
- Verify the table name is exactly
productos(lowercase) - Check that you’re connected to the correct Supabase project
No data returned from queries
No data returned from queries
- Check Row Level Security policies if enabled
- Verify data exists: run
SELECT * FROM productosin SQL Editor - Check browser console for error messages
Environment variables not loading
Environment variables not loading
- Ensure file is named exactly
.env.local(not.env) - Variables must start with
VITE_prefix - Restart the Vite dev server with
npm run dev
Next Steps
Environment Variables
Learn how to configure your
.env.local fileProject Structure
Understand how Supabase integrates with the app
Supabase Docs
Official Supabase documentation
Supabase JS Client
JavaScript client library reference
