Skip to main content
Get your CEDIS Pedidos development environment up and running quickly. This guide will walk you through the complete setup process from cloning the repository to running the application locally.

Prerequisites

Before you begin, ensure you have the following installed on your system:
  • Node.js (v18 or higher) - Download here
  • npm, yarn, or pnpm package manager
  • Git for version control
  • A Supabase account - Sign up here
This application requires a Supabase project with the proper database schema and Row Level Security (RLS) policies configured. See the Database Setup guide for details.

Installation Steps

1

Clone the Repository

Start by cloning the CEDIS Pedidos repository to your local machine:
git clone https://github.com/AlejandroMartinezG/App_Pedidos_CEDIS.git
cd App_Pedidos_CEDIS
2

Install Dependencies

Install all required dependencies using your preferred package manager:
npm install
This will install all the dependencies listed in package.json, including:
  • React 19 and React Router for the frontend
  • @supabase/supabase-js for database and authentication
  • Tailwind CSS v4 and Radix UI for styling and components
  • Vite for fast development and building
3

Configure Environment Variables

Create a .env file in the root directory of your project and add your Supabase credentials:
.env
VITE_SUPABASE_URL=your_supabase_project_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
Never commit your .env file to version control. The .gitignore file should already exclude it, but always verify before pushing code.

Getting Your Supabase Credentials

  1. Go to your Supabase Dashboard
  2. Select your project
  3. Navigate to SettingsAPI
  4. Copy the Project URL and anon/public key
The application validates these environment variables on startup. If they’re missing, you’ll see an error: “Missing Supabase environment variables. Check .env file.” (see src/lib/supabase.ts:7)
4

Start the Development Server

Launch the Vite development server:
npm run dev
The application will start on http://localhost:5173 by default. The development server includes:
  • Hot Module Replacement (HMR) for instant updates
  • Network access enabled to test on other devices on your network
5

Verify the Setup

Open your browser and navigate to http://localhost:5173. You should see the login page of the CEDIS Pedidos application.
On first run, you’ll need to create a user account or use superadmin credentials. Superadmin accounts are auto-approved based on the email list in src/context/AuthContext.tsx:33-36.

Quick Code Overview

Here’s how the application initializes and connects to Supabase:

Supabase Client Configuration

src/lib/supabase.ts
import { createClient } from '@supabase/supabase-js'

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL as string
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY as string

if (!supabaseUrl || !supabaseAnonKey) {
    throw new Error('Missing Supabase environment variables. Check .env file.')
}

export const supabase = createClient(supabaseUrl, supabaseAnonKey)

Application Entry Point

src/main.tsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './App'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
    <React.StrictMode>
        <App />
    </React.StrictMode>
)

Authentication Context

The app uses a custom AuthContext to manage user sessions and role-based access:
src/context/AuthContext.tsx
export function AuthProvider({ children }: { children: ReactNode }) {
    const [session, setSession] = useState<Session | null>(null)
    const [user, setUser] = useState<UserProfile | null>(null)
    const [loading, setLoading] = useState(true)

    useEffect(() => {
        // Load initial session
        supabase.auth.getSession().then(({ data: { session } }) => {
            handleSession(session).finally(() => setLoading(false))
        })

        // React to future auth changes
        const { data: { subscription } } = supabase.auth.onAuthStateChange(
            (_event, session) => {
                setTimeout(() => handleSession(session), 0)
            }
        )
        return () => subscription.unsubscribe()
    }, [])

    // ... authentication methods
}

Available Scripts

The following scripts are available in package.json:
ScriptCommandDescription
devviteStart the development server with HMR
buildtsc -b && vite buildType-check and build for production
linteslint .Run ESLint to check code quality
previewvite previewPreview the production build locally

Testing Your Setup

To verify everything is working correctly:
1

Check the Console

Open your browser’s developer console (F12). You should see no errors related to Supabase connection or environment variables.
2

Test Authentication

Try logging in with a test account or creating a new user. The authentication flow should work without errors.
3

Verify Routing

After login, you should be automatically redirected based on your role:
  • Admin users/dashboard
  • Sucursal users/nuevo-pedido

Common Issues

Error: Missing Supabase environment variables. Check .env file.Solution:
  • Ensure your .env file is in the project root directory
  • Verify the variable names start with VITE_ prefix
  • Restart the development server after creating/modifying .env
Error: Port 5173 is already in useSolution:
  • Kill the process using port 5173
  • Or specify a different port: vite --port 3000
Error: Authentication or database errorsSolution:
  • Verify your Supabase credentials are correct
  • Ensure your Supabase project is active
  • Check that RLS policies are properly configured
  • Verify the database schema matches the expected structure

Next Steps

Now that you have CEDIS Pedidos running locally, explore these guides:

Architecture Overview

Understand the application structure and design patterns

Database Setup

Configure your Supabase database schema and RLS policies

Authentication Guide

Learn about the role-based authentication system

Database Tables

Explore the database schema and data models
Need help? Check out the GitHub repository or review the source code for more details.

Build docs developers (and LLMs) love