📖 Scenario: You are creating a simple backend for a photo sharing app using Supabase. You will set up the main parts of Supabase architecture: a Postgres database table, authentication, storage for photos, realtime updates, and an edge function to process uploads.
🎯 Goal: Build a basic Supabase backend with a photos table in Postgres, enable user authentication, configure storage for photo files, set up realtime updates on new photos, and create an edge function to log uploads.
📋 What You'll Learn
Create a Postgres table called photos with columns id, user_id, and url
Enable authentication with email and password
Create a storage bucket called photo-uploads
Set up realtime subscription on the photos table
Write an edge function called logUpload that logs photo upload events
💡 Why This Matters
🌍 Real World
This project models a common backend architecture for apps that need user login, file storage, live updates, and serverless functions.
💼 Career
Understanding Supabase architecture is useful for junior backend developers and cloud engineers working with modern serverless platforms.
Progress0 / 4 steps
1
Create the Postgres photos table
Write the SQL command to create a table called photos with columns: id as a primary key UUID, user_id as UUID, and url as text.
Supabase
Hint
Use CREATE TABLE photos and define id as UUID primary key with default UUID generation.
2
Enable email and password authentication
Write the Supabase CLI command to enable authentication with email and password for your project.
Supabase
Hint
Use the command supabase auth enable email-password to enable email/password login.
3
Create a storage bucket called photo-uploads
Write the Supabase CLI command to create a storage bucket named photo-uploads.
Supabase
Hint
Use supabase storage create-bucket photo-uploads to create the bucket.
4
Set up realtime subscription and edge function
Write the Supabase CLI commands to subscribe to realtime changes on the photos table and create an edge function called logUpload.
Supabase
Hint
Use supabase realtime enable photos to enable realtime on the table and supabase functions new logUpload to create the edge function.
Practice
(1/5)
1. Which Supabase component is responsible for managing user sign-ups and logins?
easy
A. Storage
B. Postgres
C. Realtime
D. Auth
Solution
Step 1: Understand Supabase components
Supabase has several parts: Postgres for data, Auth for users, Storage for files, Realtime for live updates, and Edge Functions for custom code.
Step 2: Identify user management part
The component that handles user sign-ups, logins, and authentication is called Auth.
Final Answer:
Auth -> Option D
Quick Check:
User management = Auth [OK]
Hint: Auth means user login and signup system [OK]
Common Mistakes:
Confusing Postgres with user management
Thinking Storage handles users
Mixing Realtime with authentication
2. Which of the following is the correct way to initialize Supabase client in JavaScript?
easy
A. const supabase = Supabase.create('url', 'anon_key');
B. const supabase = createClient('url', 'anon_key');
C. const supabase = supabaseClient('url', 'anon_key');
D. const supabase = new Supabase('url', 'anon_key');
D. No output, subscription does not listen to INSERT
Solution
Step 1: Understand Realtime subscription
The code listens for INSERT events on the 'messages' table and logs the new row's text field.
Step 2: Analyze the callback behavior
When a new row is inserted, payload.new contains the new row data, so payload.new.text is the inserted message text.
Final Answer:
New message: [text of inserted row] -> Option A
Quick Check:
Realtime INSERT event logs new row text [OK]
Hint: INSERT event payload.new has new row data [OK]
Common Mistakes:
Expecting payload.old instead of payload.new
Thinking .subscribe() is invalid
Assuming no output on INSERT
4. You wrote this Edge Function to upload a file to Supabase Storage but it fails with a permission error. What is the likely cause?
export async function POST(request) {
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY);
const data = await request.formData();
const file = data.get('file');
const { error } = await supabase.storage.from('avatars').upload(file.name, file);
if (error) return new Response(error.message, { status: 400 });
return new Response('Upload successful');
}
medium
A. Storage upload requires user session, missing auth
B. The 'avatars' bucket does not exist
C. File object is not properly extracted from formData
D. Using SERVICE_ROLE_KEY in Edge Function is insecure and disabled
Solution
Step 1: Check authentication context for storage upload
Storage upload requires a user session or proper auth context; using service role key alone in Edge Functions does not provide user session.
Step 2: Identify missing user session
Without user session, storage upload is denied due to permission error.
Final Answer:
Storage upload requires user session, missing auth -> Option A
Quick Check:
Storage upload needs user auth session [OK]
Hint: Storage upload needs user session, not just service key [OK]
Common Mistakes:
Assuming service role key works for storage upload
Ignoring bucket existence
Not checking file extraction from formData
5. You want to build a chat app using Supabase that updates messages live and stores user avatars. Which combination of Supabase components should you use?
hard
A. Auth for messages, Edge Functions for avatars, Storage for live updates
B. Realtime for messages and avatars, Postgres for user login
C. Postgres for messages, Storage for avatars, Realtime for live updates, Auth for user login
D. Storage for messages, Postgres for avatars, Edge Functions for live updates
Solution
Step 1: Identify storage needs
Messages are structured data best stored in Postgres; avatars are files stored in Storage.
Step 2: Identify live update and user management
Realtime provides live updates for messages; Auth manages user login.
Final Answer:
Postgres for messages, Storage for avatars, Realtime for live updates, Auth for user login -> Option C
Quick Check:
Use Postgres, Storage, Realtime, Auth together [OK]
Hint: Messages in Postgres, avatars in Storage, live with Realtime [OK]
Common Mistakes:
Mixing Storage with live updates
Using Realtime for file storage
Confusing Auth with data storage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.