How we integrated Supabase authentication and database features
This project now uses Supabase for authentication instead of NextAuth.js. We've maintained backward compatibility with existing Prisma/MySQL database while adding Supabase's real-time features.
When a user makes a payment through Stripe, the webhook now updates both the MySQL database (for compatibility) and the Supabase database (for real-time features).
The Supabase database includes the following tables:
create table users (
id uuid references auth.users on delete cascade not null primary key,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
name text,
email text unique,
image text,
stripe_subscription_id text,
stripe_customer_id text,
stripe_price_id text,
stripe_current_period_end timestamp with time zone,
downloaded_at timestamp with time zone,
download_platform text
);create table posts (
id uuid default uuid_generate_v4() primary key,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
title text,
content jsonb,
published boolean default false,
author_id uuid references users(id) on delete cascade not null
);create table accounts (
id uuid default uuid_generate_v4() primary key,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
user_id uuid references users(id) on delete cascade not null,
type text not null,
provider text not null,
provider_account_id text not null,
refresh_token text,
access_token text,
expires_at bigint,
token_type text,
scope text,
id_token text,
session_state text
);create table sessions (
id uuid default uuid_generate_v4() primary key,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
session_token text not null unique,
user_id uuid references users(id) on delete cascade not null,
expires timestamp with time zone not null
);create table verification_tokens (
id uuid default uuid_generate_v4() primary key,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
identifier text not null,
token text not null unique,
expires timestamp with time zone not null
);lib/supabase/client.ts - Supabase client configurationlib/supabase/auth.ts - Authentication utilitieslib/supabase/admin.ts - Admin client for server-side operationssupabase/migrations/ - Database migration scriptsMake sure to set the following environment variables:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_keynpm install -g supabasesupabase startsupabase db push