A modern Next.js application with Clerk authentication and Supabase backend integration.
For more information, visit vibewind.com.
- 🔐 Authentication with Clerk
- 📦 Supabase Database Integration
- 🔄 Clerk-Supabase Sync
- 🛣️ Protected Routes with Middleware
- 📱 Responsive Design with Tailwind CSS
- 🎯 TypeScript Support
- 🏃♂️ Fast Development with Next.js
- Node.js (v18 or higher)
- npm or yarn
- A Clerk account
- A Supabase account
-
Clone the repository
git clone https://github.com/vibewind/vibewind-starter.git your-project-name cd your-project-nameReplace
your-project-namewith whatever name you'd like to give your project. -
Install dependencies
npm install
-
Environment Variables Create a
.env.localfile in the root directory with the following variables:# Clerk Authentication NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key CLERK_SECRET_KEY=your_clerk_secret_key # Supabase Configuration 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_key
-
Supabase Setup
Create the following table in your Supabase database:
-- Create users table create table public.users ( id uuid primary key default uuid_generate_v4(), clerk_id text not null unique, email text not null unique, first_name text, last_name text, created_at timestamptz not null default now(), updated_at timestamptz not null default now() ); -- Enable Row Level Security (RLS) alter table public.users enable row level security; -- Create policies create policy "Users can view their own data" on public.users for select using (auth.uid()::text = clerk_id); create policy "Service role can manage all users" on public.users using (auth.jwt()->>'role' = 'service_role');
-
Development
npm run dev
The application will be available at
http://localhost:3000 -
Build for Production
npm run build npm start
vibewind/
├── app/ # Next.js application routes and components
├── utils/ # Utility functions and configurations
│ ├── supabase.ts # Supabase client configuration
│ └── user-sync.ts # Clerk-Supabase user synchronization
├── types/ # TypeScript type definitions
├── middleware.ts # Authentication and routing middleware
├── public/ # Static assets
└── styles/ # Global styles and Tailwind configuration
The users table maintains synchronization between Clerk and Supabase:
id(uuid, primary key): Unique identifier for the user in Supabaseclerk_id(text, unique): Clerk's user IDemail(text, unique): User's email addressfirst_name(text, nullable): User's first namelast_name(text, nullable): User's last namecreated_at(timestamptz): Record creation timestampupdated_at(timestamptz): Record update timestamp
The following policies are enabled on the users table:
-
Read Access: Users can only view their own data
- Policy name: "Users can view their own data"
- Applies to: SELECT operations
- Check:
auth.uid()::text = clerk_id
-
Admin Access: Service role can manage all users
- Policy name: "Service role can manage all users"
- Applies to: ALL operations
- Check:
auth.jwt()->>'role' = 'service_role'
User data synchronization between Clerk and Supabase is handled by utils/user-sync.ts:
- Automatically syncs user data on authentication
- Uses upsert operation for reliable updates
- Handles both new user creation and profile updates
- Uses service role for bypassing RLS during sync
- Users can sign up/sign in using Clerk authentication
- Protected routes are managed through middleware
- User data syncs automatically between Clerk and Supabase using our custom sync utility
/- Public homepage/sign-in/*- Clerk sign-in pages/sign-up/*- Clerk sign-up pages/dashboard- Protected dashboard (requires authentication)
- Frontend: Next.js 15.0.0
- Authentication: Clerk
- Database: Supabase
- Styling: Tailwind CSS
- Language: TypeScript
- State Management: React (Context if needed)
- Use TypeScript for all new files
- Follow the existing project structure
- Use Tailwind CSS for styling
- Implement proper error handling
- Keep components modular and reusable
next.config.js- Next.js configurationtailwind.config.js- Tailwind CSS configurationtsconfig.json- TypeScript configurationmiddleware.ts- Route protection and authentication middleware
- Ensure all environment variables are properly set before running the application
- Keep your Clerk and Supabase keys secure
- Don't commit the
.env.localfile to version control - Use the service role key only for server-side operations
- Always use the user sync utility for managing user data
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - feel free to use this project as a template for your own applications.