A complete full-stack application with a high-performance API backend using Bun, Hono, and Better Auth, paired with a modern Next.js frontend with Shadcn UI.
This project consists of two main components:
- Server: A high-performance REST API built with Bun, Hono, and Better Auth
- Client: A modern Next.js 14 application with authentication UI flows
- ⚡️ Ultra-fast performance with Bun runtime
- 🧩 Modular architecture with Hono framework
- 🔒 Enhanced authentication with Better-Auth
- 🔌 MongoDB integration with both Mongoose and native client
- 🛡️ Role-based authorization with admin and user roles
- 📦 Compression support for optimized responses
- ✅ TypeScript for type safety
- 🔍 Error handling middleware
- 🛡️ CORS support for cross-origin requests
- 🚀 Next.js 14 with App Router for modern React
- 💅 Shadcn UI for beautiful, accessible components
- 🔐 Authentication flows including:
- Login & Registration
- Magic Link Authentication
- Social Login (Apple, Google, GitHub, Facebook and more)
- Email Verification
- Forgot/Reset Password
- Two-Factor Authentication
- Profile Management
- Change Password
- User Management (Admin)
- Role-Based Access Control
- Session Management
- Custom User Fields
- 📱 Responsive design for all device sizes
- 🌐 Dashboard with protected routes
- 👤 User management for admins
Before you begin, make sure you have the following installed:
- Bun (v1.0.0 or newer)
- MongoDB or MongoDB Atlas
- Node.js (v18 or newer)
- Clone this repository:
git clone https://github.com/ProMehedi/bun-hono-better-auth.git
cd bun-hono-better-auth
- Install server dependencies:
cd server
bun install
- Install client dependencies:
cd ../client
bun install
Create a .env
file in the server
directory with the following variables:
PORT=8000
MONGO_URI=mongodb://localhost:27017/betterAuth
API_BASE=/api/v1
# Better-Auth configuration
BETTER_AUTH_SECRET=your_secret_key
BETTER_AUTH_URL=http://localhost:3000
Create a .env.local
file in the client
directory with:
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
- Start the server:
cd server
bun dev
- In another terminal, start the client:
cd client
bun dev
- The API will be available at: http://localhost:8000/api/v1
- The frontend will be available at: http://localhost:3000
- Build and start the server:
cd server
bun start
- Build and start the client:
cd client
bun build
bun start
- Server Documentation: See the server README for detailed backend information.
- Client Documentation: See the client README for detailed frontend information.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Mehedi Hasan - admin@promehedi.com
Project Link: https://github.com/ProMehedi/bun-hono-better-auth