A modern authentication boilerplate using Supabase, Next.js 14, and TypeScript. This template provides a solid foundation for building applications with email authentication, protected routes, and user profiles.
- 🔐 Email Authentication
- 👤 User Profile Management
- 🛡️ Protected Routes
- 🚀 Next.js 14 App Router
- 📱 Responsive Design
- 🎨 Tailwind CSS
- ✉️ Custom Email Templates with Resend
- Node.js 18+
- A Supabase account
- A Resend account
git clone [your-repo-url]
cd supabase-auth-boilerplatenpm install- Create a new project on Supabase
- Once your project is ready, go to Project Settings > API
- Copy your project URL and anon key
- In the SQL editor, run the following commands to set up the database:
-- Create the profiles table
create table profiles (
id uuid references auth.users on delete cascade primary key,
name text,
role text,
first_login boolean default true,
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
);
-- Enable Row Level Security
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 policy "Users can insert own profile"
on profiles for insert
with check ( auth.uid() = id );
-- Create triggers
create or replace function handle_updated_at()
returns trigger as $$
begin
new.updated_at = now();
return new;
end;
$$ language plpgsql;
create trigger handle_profiles_updated_at
before update on profiles
for each row
execute procedure handle_updated_at();
create or replace function public.handle_new_user()
returns trigger as $$
begin
insert into public.profiles (id)
values (new.id);
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();- Go to Authentication > Email Templates
- Click on "Change Email Address" template
- Replace the default template with:
<h2>Confirm Email Change</h2>
<p>Follow this link to confirm the update of your email from {{ .Email }} to {{ .NewEmail }}:</p>
<p><a href="{{ .SiteURL }}/email-confirmation?token_hash={{ .TokenHash }}&type=email-change&next=/dashboard">Change Email</a></p>
<p>Or copy and paste the URL into your browser:</p>
<p>{{ .SiteURL }}/email-confirmation?token_hash={{ .TokenHash }}&type=email-change&next=/dashboard</p>
<p>If you didn't request this email change, you can safely ignore this email.</p>- Create an account at Resend
- Create an API key
- Add your domain and verify it
- Create an email template (optional)
- Copy the
.env.examplefile to.env.local:
cp .env.example .env.local- Update the
.env.localwith your credentials:
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
RESEND_API_KEY=your-resend-api-key
npm run devVisit http://localhost:3000 to see your application.
├── src/
│ ├── app/ # Next.js app router
│ │ ├── auth/ # Authentication pages
│ │ ├── dashboard/ # Protected dashboard
│ │ └── layout.tsx # Root layout
│ ├── components/ # Reusable components
│ ├── emails/ # Email templates
│ └── utils/ # Utility functions
│ └── supabase/ # Supabase client setup
├── public/ # Static assets
└── tailwind.config.js # Tailwind CSS configuration
- Users can sign up with email
- Upon first login, users are redirected to the dashboard
- A profile is automatically created for new users
- The dashboard shows a different welcome message for first-time users
- Email change requests trigger a confirmation email using custom template
- Custom email templates using Resend
- Email change confirmation
- Responsive email designs
- HTML and plain text versions
- Tracking and analytics (via Resend dashboard)
- Database Error Granting User: Make sure you've run all the SQL commands in your Supabase SQL editor
- Auth Not Working: Verify your environment variables are correctly set
- Profile Not Created: Check if the database triggers are properly set up
- Emails Not Sending:
- Verify your Resend API key is correct
- Check if your domain is properly verified in Resend
- Ensure email templates are properly configured in Supabase
Contributions are welcome! Please feel free to submit a Pull Request.
MIT