npm install -g supabase
# or
brew install supabase/tap/supabasesupabase db pushIf 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();In your Supabase dashboard:
- Go to Authentication > URL Configuration
- Set Site URL to:
http://localhost:5173 - Add Redirect URLs:
http://localhost:5173,http://127.0.0.1:5173
npm run devThe app should now:
- Show login form when not authenticated
- Redirect to role selection after login (if no role set)
- Redirect to appropriate dashboard based on role