Supabase Full Tutorial for Beginners: Build a React Sales Dashboard
freeCodeCamp.orgDecember 16, 20254h 24min28,569 views
85 connectionsΒ·40 entities in this videoβIntroduction to Supabase
- π‘ Supabase is an open-source Firebase alternative and a Backend-as-a-Service (BaaS) platform.
- π It provides database infrastructure based on Postgres with a simple setup, aiming to get developers started quickly.
- ποΈ Supabase offers backend services and client-side SDKs to connect JavaScript frameworks to its infrastructure.
Building a Sales Dashboard
- π― The project involves creating a React.js sales dashboard with user authentication, real-time data, and secure user management.
- π Features include a real-time updating chart of total sales per rep for the current quarter, and a form to add new deals.
- π οΈ The app utilizes Postgres for data storage, React for the frontend, and Supabase client library for database interactions.
Database Setup and Queries
- ποΈ A Supabase project and a
sales_dealstable are created, withname(text) andvalue(integer) columns. - π The Supabase client library (
supabase-js) is installed and initialized using environment variables for URL and API key. - π Queries are performed using SQL and translated into client-side code, including aggregate functions like
SUMandGROUP BYto calculate total sales per rep.
Authentication and Security
- π Row Level Security (RLS) is implemented to control access to database rows, ensuring only authenticated users can view or modify data.
- π JSON Web Tokens (JWTs), specifically the anon key and authenticated tokens, are explained as the mechanism for secure data transmission and verification.
- π€ A
user_profilestable is introduced to store custom user data likeaccount_type(rep or admin) andname, linked via a foreign key to theauth.userstable.
Real-time Data and Forms
- π Supabase Realtime subscriptions are set up to listen for database changes (inserts, updates, deletes) and update the dashboard in real-time.
- π A form is built using React's
useActionStatehook to allow users to add new deals, with input validation and submission handling. - π The
sign_upandsign_infunctions are implemented using Supabase's authentication methods, managing user sessions and JWTs.
Refactoring and Policies
- π The
sales_dealstable is refactored to useuser_id(UUID) instead ofnamefor row ownership, linking to theuser_profilestable. - π‘οΈ RLS policies are created to enforce granular access control, allowing reps to add only their own deals and admins to add deals for any user.
- βοΈ A Postgres trigger (
handle_new_user) is implemented to automatically populate theuser_profilestable upon new user creation inauth.users, ensuring data consistency.
Knowledge graph40 entities Β· 85 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
40 entities
Chapters20 moments
Key Moments
Transcript965 segments
Full Transcript
Topics21 themes
Whatβs Discussed
SupabasePostgresReact.jsBackend-as-a-ServiceBaaSDatabaseAuthenticationReal-time DataRow Level SecurityRLSJWTJSON Web TokensUser ManagementData VisualizationSales DashboardFrontend DevelopmentBackend DevelopmentSQLClient-side SDKTriggersForeign Keys
Smart Objects40 Β· 85 links
CompaniesΒ· 6
ConceptsΒ· 23
MediasΒ· 5
PeopleΒ· 2
ProductsΒ· 4