This guide explains how to set up Supabase for the URL shortener with Google authentication and link analytics.
- A Supabase account (free tier works fine)
- A Google Cloud Console account for OAuth
- Go to supabase.com and sign in
- Click "New Project"
- Fill in:
- Name: Your project name (e.g., "article-idea-generator")
- Database Password: Generate a strong password (save it!)
- Region: Choose the closest to your users
- Click "Create new project" and wait for it to initialize
- In your Supabase dashboard, go to SQL Editor
- Open the file
supabase/schema.sqlfrom this project - Copy the entire contents and paste it into the SQL Editor
- Click "Run" to execute the schema
This creates:
profilestable for user datashort_urlstable for shortened URLsclick_eventstable for analytics- Row Level Security (RLS) policies
- Necessary functions and triggers
- Go to console.cloud.google.com
- Create a new project or select an existing one
- Go to APIs & Services > OAuth consent screen
- Choose "External" user type
- Fill in required fields (App name, User support email, Developer contact)
- Add scopes:
email,profile,openid - Add test users if in testing mode
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Application type: Web application
- Name: Your app name
- Authorized JavaScript origins:
http://localhost:3000(for development)https://your-production-domain.com
- Authorized redirect URIs:
http://localhost:3000/auth/callbackhttps://your-production-domain.com/auth/callbackhttps://<your-project-ref>.supabase.co/auth/v1/callback
- Save the Client ID and Client Secret
- Go to Authentication > Providers
- Find Google and enable it
- Enter your Google Client ID and Client Secret
- Save changes
Create or update your .env.local file:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://<your-project-ref>.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=<your-anon-key>
# Site URL (for auth redirects)
NEXT_PUBLIC_SITE_URL=http://localhost:3000- Go to your Supabase project dashboard
- Click Settings (gear icon) > API
- Copy:
- Project URL →
NEXT_PUBLIC_SUPABASE_URL - anon public key →
NEXT_PUBLIC_SUPABASE_ANON_KEY
- Project URL →
In Supabase dashboard:
- Go to Authentication > URL Configuration
- Set:
- Site URL:
http://localhost:3000(for dev) or your production URL - Redirect URLs: Add all allowed redirect URLs:
http://localhost:3000/auth/callbackhttps://your-production-domain.com/auth/callback
- Site URL:
-
Start your development server:
npm run dev
-
Go to
http://localhost:3000/tools/url-shortener -
Click "Sign in with Google" in the header
-
After signing in, create a short URL - it should be saved to Supabase
-
Check your dashboard at
/dashboardto see your links and analytics
- Create short URLs (saved to database, but without user association)
- QR code generation for any shortened link
- Copy short links to clipboard
- Local link history in browser
- Redirects work for all URLs
- All anonymous features, plus:
- Links associated with your account
- Links synced across devices
- Persistent storage in Supabase
- Detailed analytics dashboard with:
- Click counts (total, unique, QR scans)
- Geographic breakdown (country, city)
- Device and browser statistics
- Traffic source analysis
- Referrer tracking
- Timeline data
- Recent click history
- Dashboard for managing all links
profiles
id(UUID, references auth.users)email(text)full_name(text)avatar_url(text)created_at,updated_at(timestamps)
short_urls
id(UUID)user_id(UUID, nullable - anonymous URLs allowed)code(varchar 10, unique)original_url(text)title(text)click_count,unique_click_count,qr_scan_count(integers)created_at,updated_at(timestamps)
click_events
id(UUID)short_url_id(UUID, references short_urls)ip_hash(varchar 64 - hashed for privacy)user_agent,referrer(text)country,city(varchar)device_type,browser,os(varchar)source_type(varchar - 'direct' or 'qr')utm_source,utm_medium,utm_campaign(varchar)fingerprint(varchar - for unique visitor tracking)is_unique(boolean)created_at(timestamp)
- Double-check your
NEXT_PUBLIC_SUPABASE_ANON_KEYin.env.local - Make sure you're using the anon key, not the service role key
- Verify redirect URIs match exactly in Google Console and Supabase
- Check that Google provider is enabled in Supabase Authentication settings
- Ensure your Google Cloud project has the OAuth consent screen configured
- Make sure you ran the full
schema.sqlfile - Check that RLS is enabled on all tables
- Verify policies were created (check in Supabase > Table Editor > Policies)
- Check browser console for API errors
- Verify the user is properly authenticated
- Check Supabase logs in the dashboard
- Update environment variables in your hosting platform (Vercel, etc.)
- Update Google OAuth redirect URIs with production domain
- Update Supabase URL Configuration with production URL
- Test the complete flow on production