Skip to content

ProMehedi/bun-hono-better-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bun Hono Better Auth Full-Stack Application

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.

Project Overview

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

Features

Backend (Server)

  • ⚡️ 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

Frontend (Client)

  • 🚀 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

Getting Started

Prerequisites

Before you begin, make sure you have the following installed:

Installation

  1. Clone this repository:
git clone https://github.com/ProMehedi/bun-hono-better-auth.git
cd bun-hono-better-auth
  1. Install server dependencies:
cd server
bun install
  1. Install client dependencies:
cd ../client
bun install

Configuration

Server

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

Client

Create a .env.local file in the client directory with:

NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1

Running the Application

Development Mode

  1. Start the server:
cd server
bun dev
  1. In another terminal, start the client:
cd client
bun dev

Production Mode

  1. Build and start the server:
cd server
bun start
  1. Build and start the client:
cd client
bun build
bun start

Documentation

  • Server Documentation: See the server README for detailed backend information.
  • Client Documentation: See the client README for detailed frontend information.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Contact

Mehedi Hasan - admin@promehedi.com

Project Link: https://github.com/ProMehedi/bun-hono-better-auth

About

A high-performance full-stack template using Bun, Hono, and Better Auth with MongoDB integration.

Topics

Resources

Stars

Watchers

Forks