Skip to content

Latest commit

 

History

History
69 lines (57 loc) · 1.8 KB

File metadata and controls

69 lines (57 loc) · 1.8 KB

Supabase Setup Instructions

1. Install Supabase CLI

npm install -g supabase
# or
brew install supabase/tap/supabase

2. Run the migration

supabase db push

3. Alternative: Manual Setup

If you prefer to set up manually, go to your Supabase dashboard and run this SQL:

-- Create profiles table
CREATE TABLE IF NOT EXISTS profiles (
  id UUID REFERENCES auth.users(id) ON DELETE CASCADE PRIMARY KEY,
  email TEXT,
  app_role TEXT DEFAULT 'employee' CHECK (app_role IN ('administrator', 'employee')),
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Enable RLS
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;

-- Create policies
CREATE POLICY "Users can view own profile" ON profiles
  FOR SELECT USING (auth.uid() = id);

CREATE POLICY "Users can update own profile" ON profiles
  FOR UPDATE USING (auth.uid() = id);

-- Create function to handle new user registration
CREATE OR REPLACE FUNCTION handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
  INSERT INTO profiles (id, email)
  VALUES (NEW.id, NEW.email);
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

-- Create trigger for new user registration
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
CREATE TRIGGER on_auth_user_created
  AFTER INSERT ON auth.users
  FOR EACH ROW EXECUTE FUNCTION handle_new_user();

4. Update Supabase Project Settings

In your Supabase dashboard:

  1. Go to Authentication > URL Configuration
  2. Set Site URL to: http://localhost:5173
  3. Add Redirect URLs: http://localhost:5173, http://127.0.0.1:5173

5. Test the Application

npm run dev

The app should now:

  1. Show login form when not authenticated
  2. Redirect to role selection after login (if no role set)
  3. Redirect to appropriate dashboard based on role