Mạng xã hội đầy đủ tính năng xây dựng với Next.js 16 + Supabase.
- Truy cập supabase.com → New Project
- Đặt tên project, chọn region (Singapore gần nhất)
- Vào Settings → API → Copy:
Project URL→NEXT_PUBLIC_SUPABASE_URLanon publickey →NEXT_PUBLIC_SUPABASE_ANON_KEYservice_rolekey →SUPABASE_SERVICE_ROLE_KEY
# Sao chép file mẫu
cp .env.example .env.localĐiền giá trị thực vào .env.local:
NEXT_PUBLIC_SUPABASE_URL=https://xxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGci...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGci...- Vào Supabase Dashboard → SQL Editor
- Copy toàn bộ nội dung file
supabase/migrations/001_initial_schema.sql - Paste vào SQL Editor → Run
Migration sẽ tạo:
- ✅ 13 tables (profiles, posts, reactions, comments, follows, notifications, messages, conversations, hashtags, blocks, reports...)
- ✅ Row Level Security (RLS) policies
- ✅ Triggers (auto-create profile khi đăng ký, updated_at)
- ✅ Storage buckets (avatars, posts, messages)
- ✅ Full-text search indexes
Google OAuth:
- console.cloud.google.com → Create Project
- APIs & Services → Credentials → OAuth 2.0 Client ID
- Authorized redirect URI:
https://your-project.supabase.co/auth/v1/callback - Supabase Dashboard → Authentication → Providers → Google → bật ON
GitHub OAuth:
- github.com/settings/developers → New OAuth App
- Authorization callback URL:
https://your-project.supabase.co/auth/v1/callback - Supabase Dashboard → Authentication → Providers → GitHub → bật ON
Supabase Dashboard → Authentication → URL Configuration:
- Site URL:
http://localhost:3000(dev) hoặc domain của bạn - Redirect URLs: thêm
http://localhost:3000/**
npm install
npm run dev
src/
├── app/
│ ├── (auth)/ # Login, Register, Forgot password
│ │ ├── login/
│ │ ├── register/
│ │ └── forgot-password/
│ ├── (main)/ # Các trang chính (cần đăng nhập)
│ │ ├── feed/ # Trang chủ
│ │ ├── profile/[username]/
│ │ ├── posts/[id]/
│ │ ├── notifications/
│ │ ├── messages/
│ │ ├── search/
│ │ ├── hashtags/[tag]/
│ │ └── admin/
│ ├── auth/callback/ # OAuth callback
│ └── layout.tsx
├── components/
│ ├── layout/ # Sidebar, MobileNav
│ ├── posts/ # PostCard, CreatePostModal, CommentsSection
│ ├── profile/ # EditProfileModal
│ └── ui/ # Avatar
├── lib/supabase/ # Supabase clients
├── types/ # TypeScript types
└── proxy.ts # Route protection (Next.js 16)
| Module | Tính năng |
|---|---|
| 🔐 Auth | Email/Password, Google OAuth, GitHub OAuth, Quên mật khẩu |
| 👤 Profile | Avatar upload, Bio, Website, Follow/Unfollow |
| 📝 Posts | Tạo/Xóa, Ảnh (tối đa 4), Quyền riêng tư, Hashtag tự động |
| ❤️ Reactions | 6 loại emoji (Like, Love, Haha, Wow, Sad, Angry) |
| 💬 Comments | Bình luận lồng nhau (nested), Realtime |
| 👥 Follow | Follow/Unfollow, Feed cá nhân hóa |
| 🔔 Notifications | Push realtime, Đánh dấu đã đọc |
| ✉️ Messages | Chat 1-1 realtime, Read receipts |
| 🔍 Search | Full-text search users/posts/hashtags |
| # Hashtags | Tự động extract, Trending, Explore |
| ⚡ Realtime | Supabase Realtime WebSocket |
| 🛡️ Admin | Dashboard stats, Xóa user/post |
- Framework: Next.js 16.2 (App Router, Turbopack)
- Backend: Supabase (PostgreSQL, Auth, Storage, Realtime)
- Styling: Vanilla CSS Modules (Dark mode)
- Language: TypeScript
- Realtime: Supabase Realtime (WebSocket)
npm run dev # Development server
npm run build # Production build
npm run start # Start production server
npm run lint # Lint code