Create a Supabase project
- Go to supabase.com and sign in or create a free account.
- Click New project.
- Choose an organization, give the project a name (e.g.
sazon-comunitario), and set a strong database password. - Select the region closest to your users and click Create new project.
Get your project credentials
You need two values from your Supabase project settings:
- Open your project in the Supabase dashboard.
- Navigate to Project Settings → API.
- Copy the Project URL and the anon / public key.
.env.local file in a later step.Create the database tables
Open the SQL Editor in your Supabase dashboard and run the following statements.
Set up Supabase Storage buckets
The upload endpoint (
POST /api/upload) uses two storage buckets — one for recipe images and one for user avatars. Create both buckets in the Supabase dashboard:- Navigate to Storage in your Supabase project.
- Click New bucket and create a bucket named
recetas. Set it to Public. - Click New bucket again and create a bucket named
avatars. Set it to Public.
getPublicUrl().The upload route accepts any bucket name passed in the
bucket form field. The file is named receta-{userId}-{timestamp}.{ext} for recipe images and avatar-{userId}-{timestamp}.{ext} for avatars. Images larger than 5 MB are rejected by the API before reaching storage.Configure Row Level Security
Supabase enables Row Level Security (RLS) on all tables by default. The application performs all data access through server-side Next.js API routes using the Supabase server client, which inherits the authenticated user’s session from cookies.Because all writes are validated and authorized in the API routes before the Supabase query is executed, you can keep RLS policies permissive for the service role while restricting direct client access.A minimal setup is to enable RLS on all three tables and add a policy that allows all operations for authenticated users:
RLS policies
Add environment variables
Create a Both variables are prefixed with
.env.local file in the root of the Next.js project and add the credentials you copied in step 2:.env.local
NEXT_PUBLIC_ so they are available in the browser Supabase client (src/utils/supabase/client.js) as well as in server-side API routes.If you are deploying to Vercel, add these same variables in Project Settings → Environment Variables instead of committing the file.
Verify the setup
After completing all steps, start the development server and confirm the following:- Registering a new user creates a row in
perfileswithbloqueado = falseandis_admin = false. - Logging in as that user succeeds and returns a session.
- Creating a recipe inserts a row in
recetaswithoculta = false. - Uploading an image returns a public URL from the
recetasoravatarsbucket.
http://localhost:3000 and walk through registration and recipe creation to confirm the database connection is working correctly.