Skip to main content

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_deals table are created, with name (text) and value (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 SUM and GROUP BY to 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_profiles table is introduced to store custom user data like account_type (rep or admin) and name, linked via a foreign key to the auth.users table.

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 useActionState hook to allow users to add new deals, with input validation and submission handling.
  • πŸš€ The sign_up and sign_in functions are implemented using Supabase's authentication methods, managing user sessions and JWTs.

Refactoring and Policies

  • πŸ”„ The sales_deals table is refactored to use user_id (UUID) instead of name for row ownership, linking to the user_profiles table.
  • πŸ›‘οΈ 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 the user_profiles table upon new user creation in auth.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