A modern, fully modularized web application built with Next.js 15, featuring complete authentication system with email/password and OAuth support, PostgreSQL/Supabase database integration, and a comprehensive user schema.
- Email & Password Authentication - Secure login with hashed passwords
- OAuth Integration - Google Sign-In support
- Multi-step Registration - User-friendly signup process
- Session Management - JWT-based sessions with NextAuth.js
- Protected Routes - Automatic redirection for authenticated routes
- Comprehensive User Schema including:
- Personal Information (Name, Contact, Email)
- Location Data (Country, Current City, Address)
- Optional Fields (Birthday, Gender, Profile Picture)
- Address Details (Line 1, Line 2, Landmark, Pin, City, State)
- Next.js 15 with App Router
- TypeScript for type safety
- Tailwind CSS for styling
- NextAuth.js for authentication
- Supabase/PostgreSQL for database
- Zod for schema validation
- React Hook Form for form handling
src/
βββ app/
β βββ api/auth/ # Authentication API routes
β βββ auth/ # Auth pages (signin, signup)
β βββ dashboard/ # Protected dashboard
β βββ layout.tsx # Root layout with providers
βββ components/
β βββ auth/ # Authentication components
β β βββ signin-form.tsx
β β βββ signup-form.tsx
β β βββ auth-provider.tsx
β βββ ui/ # Reusable UI components
β βββ button.tsx
β βββ input.tsx
β βββ label.tsx
β βββ select.tsx
β βββ card.tsx
βββ lib/
β βββ auth.ts # Authentication utilities
β βββ schemas.ts # Zod validation schemas
β βββ supabase.ts # Supabase client configuration
β βββ utils.ts # Utility functions
βββ types/
βββ user.ts # TypeScript type definitions
Create a .env.local file based on .env.example:
# NextAuth Configuration
NEXTAUTH_SECRET=your-secret-key-here
NEXTAUTH_URL=http://localhost:3000
# Google OAuth (Optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# 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- Create a new Supabase project
- Run the SQL commands from
database-schema.sqlin your Supabase SQL editor - This will create the
userstable with all required fields and proper indexing
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth credentials
- Add your domain to authorized origins
- Add the credentials to your environment variables
npm install
npm run dev- Step 1: Email, password, and password confirmation
- Step 2: Personal information (name, phone, location, etc.)
- Validation: Real-time form validation with Zod schemas
- Storage: Secure password hashing and user creation
- Email/Password: Traditional authentication
- Google OAuth: One-click sign-in with Google
- Session Management: Automatic session handling
The user table includes comprehensive fields:
users (
id UUID PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
country_code VARCHAR(10) NOT NULL,
phone_number VARCHAR(20) NOT NULL,
country VARCHAR(100) NOT NULL,
current_city VARCHAR(100) NOT NULL,
birthday DATE,
gender VARCHAR(20),
profile_picture_url TEXT,
address JSONB,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
)- Button - Multiple variants (default, outline, ghost, destructive)
- Input - Styled form inputs with focus states
- Label - Form labels with proper accessibility
- Select - Dropdown selects
- Card - Container components with header, content, footer
- SignInForm - Complete sign-in form with validation
- SignUpForm - Multi-step registration form
- AuthProvider - Session provider wrapper
- Clone the repository
- Copy
.env.exampleto.env.localand fill in your values - Set up your Supabase database using the provided schema
- Install dependencies:
npm install - Run the development server:
npm run dev - Visit
http://localhost:3000to see the app
This repo currently uses a single database-schema.sql. To move to Supabase CLI migrations:
- Install Supabase CLI (see docs)
- Initialize:
supabase init
- Link to your project:
supabase link --project-ref <your-project-ref>
- Create an initial migration:
supabase migration new init_schema- Copy the contents of
database-schema.sqlintosupabase/migrations/<timestamp>_init_schema.sql
- Apply locally:
supabase startsupabase migration up
- Push to remote:
supabase db push
Going forward, add new SQL changes as separate files under supabase/migrations/ instead of editing database-schema.sql directly.
'use client';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
export default function ProtectedPage() {
const { data: session, status } = useSession();
const router = useRouter();
useEffect(() => {
if (status === 'loading') return;
if (!session) router.push('/auth/signin');
}, [session, status, router]);
if (!session) return null;
return <div>Protected content</div>;
}import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { signInSchema } from '@/lib/schemas';
const { register, handleSubmit, formState: { errors } } = useForm({
resolver: zodResolver(signInSchema),
});- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js team for the amazing framework
- Supabase for the backend infrastructure
- NextAuth.js for authentication
- Tailwind CSS for styling
- All the open-source contributors
Built with β€οΈ using modern web technologies