Follow these steps to set up Supabase authentication for your Vibe Prompting application.
- Go to https://supabase.com
- Sign up for a free account or log in
- Click "New Project"
- Fill in the project details:
- Name: Vibe Prompting (or your preferred name)
- Database Password: Choose a strong password (save this!)
- Region: Select the closest region to your users
- Pricing Plan: Free tier is perfect to start
- Click "Create new project"
- Wait for the project to finish setting up (1-2 minutes)
- Once your project is ready, go to Settings (gear icon in the sidebar)
- Click on API in the settings menu
- You'll see two important values:
- Project URL - This is your
VITE_SUPABASE_URL - anon public key - This is your
VITE_SUPABASE_ANON_KEY
- Project URL - This is your
- Copy these values to your
.envfile
Open the .env file in the root of your project and add:
VITE_SUPABASE_URL=https://your-project-id.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key-hereImportant:
- Replace the values with your actual credentials from Step 2
- Don't commit the
.envfile to Git (it's already in.gitignore) - Keep your keys secure!
- In your Supabase dashboard, go to Authentication β Providers
- Make sure Email is enabled (it should be by default)
- Configure email settings:
- You can use Supabase's built-in email service for development
- For production, you may want to set up a custom SMTP provider
By default, Supabase requires email confirmation. You have two options:
Option A: Keep Email Confirmation (Recommended for Production)
- Users will receive a confirmation email after signing up
- They must click the link to activate their account
- More secure but requires email setup
Option B: Disable Email Confirmation (Quick Start for Development)
- Go to Authentication β Settings β Auth Providers
- Scroll down to Email Auth
- Uncheck "Enable email confirmations"
- Click Save
- In Supabase dashboard, go to Authentication β Providers
- Find Google and click on it
- Toggle Enable Sign in with Google
- You'll need to create a Google OAuth app:
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Go to Credentials β Create Credentials β OAuth 2.0 Client ID
- Choose Web application
- Add authorized redirect URI:
https://your-project-id.supabase.co/auth/v1/callback - Copy the Client ID and Client Secret
- Paste the Client ID and Client Secret into Supabase
- Click Save
- In Supabase dashboard, go to Authentication β Providers
- Find GitHub and click on it
- Toggle Enable Sign in with GitHub
- You'll need to create a GitHub OAuth app:
- Go to GitHub Developer Settings
- Click New OAuth App
- Fill in the details:
- Application name: Vibe Prompting
- Homepage URL: Your app URL (e.g., http://localhost:5174 for development)
- Authorization callback URL:
https://your-project-id.supabase.co/auth/v1/callback
- Click Register application
- Copy the Client ID
- Generate a new Client Secret and copy it
- Paste the Client ID and Client Secret into Supabase
- Click Save
Your app stores usernames in the user metadata. This is already configured in the code:
// When signing up, we store the username
const { error } = await supabase.auth.signUp({
email,
password,
options: {
data: {
username: username, // This is stored in user metadata
},
},
})To access the username later:
const { data: { user } } = await supabase.auth.getUser()
const username = user?.user_metadata?.usernameLater, you'll want to create tables for prompts, favorites, etc. For now, authentication will work without additional tables.
When you're ready, you can create tables in the SQL Editor:
-- Users profile table (extends auth.users)
CREATE TABLE public.profiles (
id UUID REFERENCES auth.users(id) PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
avatar_url TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Enable Row Level Security
ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;
-- Profiles are viewable by everyone
CREATE POLICY "Public profiles are viewable by everyone"
ON public.profiles FOR SELECT
USING (true);
-- Users can update their own profile
CREATE POLICY "Users can update own profile"
ON public.profiles FOR UPDATE
USING (auth.uid() = id);- Make sure your
.envfile has the correct credentials - Restart your development server:
npm run dev
- Navigate to http://localhost:5174/signup
- Try signing up with:
- Email and password
- Google OAuth
- GitHub OAuth
- Check the Authentication β Users section in Supabase to see your new user
- Double-check your
.envfile has the correct values - Make sure you've restarted the dev server after adding env vars
- Check your email spam folder
- Consider disabling email confirmation for development (see Step 4)
- For production, set up a custom SMTP provider
- Verify the callback URLs match exactly
- Make sure you've enabled the provider in Supabase
- Check that Client ID and Secret are correct
- Wait a few minutes for your Supabase project to fully initialize
- Check your internet connection
- Verify your Supabase project is active
Once authentication is working:
- β Test login, signup, and logout flows
- β Create protected routes for authenticated users
- β Build the browse prompts page
- β Create prompt submission form
- β Add favorites functionality
- β Implement admin moderation
- Never commit your
.envfile - Use Row Level Security (RLS) for all database tables
- Validate user input on both client and server
- Use HTTPS in production
- Keep your Supabase packages updated
- Monitor usage in the Supabase dashboard
If you prefer a server-side, automatic sync (so provider/OAuth users always get a profile row), add a Postgres function + trigger in the Supabase SQL editor. This keeps the copy logic inside the database and avoids relying on client code.
Run this in the Supabase SQL editor (adjust table name public.profiles if you named it differently):
-- create function to upsert profile when a new auth.user is created
create or replace function public.handle_new_auth_user()
returns trigger as $$
begin
-- Try to insert a profile for the new auth user. If it exists, do nothing.
insert into public.profiles (id, username, avatar_url, created_at)
values (new.id, (new.user_metadata->>'username')::text, (new.user_metadata->>'avatar_url')::text, now())
on conflict (id) do update set
username = coalesce(excluded.username, public.profiles.username),
avatar_url = coalesce(excluded.avatar_url, public.profiles.avatar_url);
return new;
end;
$$ language plpgsql security definer;
-- attach trigger to auth.users (fires on insert)
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_auth_user();Notes:
- You must create the
public.profilestable first and ensure RLS/policies allow the trigger to write (the function is created as SECURITY DEFINER to help with permissions). - This approach guarantees that any user created in
auth.users(including GitHub/Google provider users) will get a corresponding profile row.