π₯ Stop Wasting Time with APIs β Build a Full Backend in Minutes using Supabase & React!
Imagine building a full-stack app with authentication, file uploads, and a powerful SQL database... and writing almost no backend code. Sound too good to be true? Let me show you how Supabase makes it possible.
If you're tired of setting up backends, managing authentication, or just want to ship your product faster, Supabase is your new best friend. In this post, we'll build a full-stack React app with user authentication, a Postgres database, and real-time updates β all powered by Supabase.
Supabase is an open-source alternative to Firebase. It gives you:
Unlike Firebase, Supabase is built on PostgreSQL, which means you get full SQL power and relational queries.
Weβll build a simple Notes app with:
Letβs go! π οΈ
New Project
Settings -> API
tab and copy your anon key & project URLWeβll use these in our React app.
In your Supabase dash:
-- SQL Editor create table notes ( id uuid primary key default gen_random_uuid(), user_id uuid references auth.users(id), content text, inserted_at timestamp with time zone default timezone('utc', now()) );
Now letβs build the React frontend.
Using Vite for speed:
npm create vite@latest supabase-notes --template react cd supabase-notes npm install npm i @supabase/supabase-js
Create a file: src/supabaseClient.js
import { createClient } from '@supabase/supabase-js'; const supabaseUrl = 'https://your-project.supabase.co'; const supabaseAnonKey = 'your-anon-key'; export const supabase = createClient(supabaseUrl, supabaseAnonKey);
In App.jsx
:
import { useState, useEffect } from 'react'; import { supabase } from './supabaseClient'; function App() { const [session, setSession] = useState(null); useEffect(() => { supabase.auth.getSession().then(({ data: { session } }) => { setSession(session); }); const { data: listener } = supabase.auth.onAuthStateChange((event, session) => { setSession(session); }); return () => listener.subscription.unsubscribe(); }, []); if (!session) return <Auth />; return <Notes user={session.user} />; } function Auth() { const [email, setEmail] = useState(''); const handleLogin = async () => { await supabase.auth.signInWithOtp({ email }); alert('Check your email for the login link!'); }; return ( <div> <h2>Login via Magic Link</h2> <input value={email} onChange={(e) => setEmail(e.target.value)} /> <button onClick={handleLogin}>Send</button> </div> ); }
Supabase magic link auth makes signing in a breeze.
Let's implement our Notes
component:
function Notes({ user }) { const [notes, setNotes] = useState([]); const [newNote, setNewNote] = useState(''); useEffect(() => { fetchNotes(); const realTimeSub = supabase .channel('public:notes') .on('postgres_changes', { event: '*', schema: 'public', table: 'notes' }, payload => { console.log('Realtime update', payload); fetchNotes(); }) .subscribe(); return () => supabase.removeChannel(realTimeSub); }, []); async function fetchNotes() { const { data, error } = await supabase .from('notes') .select('*') .eq('user_id', user.id) .order('inserted_at', { ascending: false }); setNotes(data); } async function addNote() { await supabase.from('notes').insert({ content: newNote, user_id: user.id }); setNewNote(''); } async function deleteNote(id) { await supabase.from('notes').delete().eq('id', id); } return ( <div> <h2>My Notes</h2> <input value={newNote} onChange={(e) => setNewNote(e.target.value)} /> <button onClick={addNote}>Add</button> <ul> {notes.map(note => ( <li key={note.id}> {note.content} <button onClick={() => deleteNote(note.id)}>x</button> </li> ))} </ul> </div> ); }
Boom β You now have real-time, collaborative notes.
VITE_SUPABASE_URL
VITE_SUPABASE_ANON_KEY
Then deploy!
Row Level Security
for extra protection on your tablesSupabase is a total game-changer for developers who want to iterate quickly and still maintain control.
You're using real SQL, you own your data, and you get Firebase-level power β‘οΈ without vendor lock-in.
Have you tried Supabase? Tweet me your builds @CodeWizardDev π§ββοΈ
Thanks for reading β time to stop writing backends and start building products! π
π If you need this done β we offer fullstack development services.
Information