Skip to content
Giorgi Gvimradze edited this page Jul 5, 2024 · 8 revisions

Welcome to the Supabase Ads Website Project!

This project is designed to create a simple ads website where users can register with social accounts, post ads, view ads, and have different roles like user, public, and administrator.

Features

  • User authentication with social accounts
  • Role-based access control
  • CRUD operations for ads
  • Real-time updates
  • Admin interface

Technologies

  • Frontend: (React/Vue/Angular)
  • Backend: Supabase (PostgreSQL, Auth, Storage)
  • Hosting: (Vercel/Netlify/Other)

Getting Started

Prerequisites

  • Node.js and npm installed
  • Supabase account
  • Git installed

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/your-repo.git
    cd your-repo
  2. Install dependencies:

    npm install
  3. Set up environment variables:

    Create a .env file in the root directory and add your Supabase project URL and anon key:

    REACT_APP_SUPABASE_URL=your-supabase-url
    REACT_APP_SUPABASE_ANON_KEY=your-supabase-anon-key

Running the Project

npm start

This will start the development server. Open http://localhost:3000 to view it in the browser.

Project Structure

/src
  /components    # React components
  /pages         # Page components
  /services      # Supabase client and API calls
  /styles        # CSS/SCSS files
  /utils         # Utility functions
.env             # Environment variables
package.json     # Project dependencies and scripts
README.md        # Project documentation

Database Schema

Profiles Table

Column Type Description
id UUID Primary key, references auth.users
username Text Unique username
created_at Timestamp Auto-generated creation time

Ads Table

Column Type Description
id UUID Primary key, auto-generated
user_id UUID References profiles(id)
title Text Ad title
description Text Ad description
created_at Timestamp Auto-generated creation time

Authentication

Social Providers

To enable social providers:

  1. Navigate to the "Authentication" tab in your Supabase dashboard.
  2. Enable desired social providers (e.g., Google, Facebook).

Email/Password Authentication

To enable email/password authentication:

  1. Navigate to the "Authentication" tab in your Supabase dashboard.
  2. Enable email/password sign-in.

Role-Based Access Control

Policies

  1. Public can view their own profile:

    create policy "Public can view their own profile."
    on profiles for select
    using (auth.uid() = id);
  2. Public can view all ads:

    create policy "Public can view all ads."
    on ads for select
    using (true);
  3. Users can insert their own ads:

    create policy "Users can insert their own ads."
    on ads for insert
    using (auth.role() = 'user');
  4. Admins can do anything:

    create policy "Admins can do anything."
    on profiles, ads for all
    using (auth.role() = 'admin');

CRUD Operations

Fetch Ads

const { data: ads, error } = await supabase
  .from('ads')
  .select('*');

Create Ad

const { data, error } = await supabase
  .from('ads')
  .insert([
    { user_id: user.id, title: 'Ad Title', description: 'Ad Description' }
  ]);

Update Ad

const { data, error } = await supabase
  .from('ads')
  .update({ title: 'Updated Title' })
  .eq('id', 'ad-id');

Delete Ad

const { data, error } = await supabase
  .from('ads')
  .delete()
  .eq('id', 'ad-id');

Deployment

  1. Build the project:

    npm run build
  2. Deploy to Vercel/Netlify:

    Follow the platform-specific instructions to deploy your build folder.

Administration

Admin Interface

  • Create an admin interface for managing users and ads.
  • Restrict access using role-based access control.

This wiki structure provides a comprehensive guide for setting up and developing your ads website project using Supabase. You can adapt and expand it based on your specific needs and updates to the project.

Clone this wiki locally