|
| 1 | +# Nuxt Template (Better Auth + Prisma + SQLite) |
| 2 | + |
| 3 | +A modern, production-ready Nuxt 4 template featuring a robust authentication system, ORM integration, and a clean UI foundation. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Nuxt 4**: The latest and greatest from the Nuxt team. |
| 8 | +- **Better Auth**: Comprehensive authentication with **Email OTP** support. |
| 9 | +- **Prisma**: Type-safe ORM for interacting with the database. |
| 10 | +- **SQLite**: Lightweight, zero-configuration database, ideal for development and small-to-medium projects. |
| 11 | +- **Nuxt UI v3**: Beautiful, accessible, and customizable UI components built with Tailwind CSS. |
| 12 | +- **Nodemailer**: Pre-configured for sending verification emails via Gmail. |
| 13 | + |
| 14 | +## Stack |
| 15 | + |
| 16 | +- **Framework**: [Nuxt](https://nuxt.com/) |
| 17 | +- **Auth**: [Better Auth](https://www.better-auth.com/) |
| 18 | +- **ORM**: [Prisma](https://www.prisma.io/) |
| 19 | +- **Database**: [SQLite](https://sqlite.org/) |
| 20 | +- **UI Framework**: [Nuxt UI](https://ui3.nuxt.com/) |
| 21 | +- **Email**: [Nodemailer](https://nodemailer.com/) |
| 22 | + |
| 23 | +## Getting Started |
| 24 | + |
| 25 | +### 1. Clone the repository |
| 26 | + |
| 27 | +```bash |
| 28 | +git clone <your-repo-url> |
| 29 | +cd nuxt-template |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Install dependencies |
| 33 | + |
| 34 | +This project uses `pnpm`, but you can use `npm` as well. |
| 35 | + |
| 36 | +```bash |
| 37 | +pnpm install |
| 38 | +``` |
| 39 | + |
| 40 | +### 3. Setup Environment Variables |
| 41 | + |
| 42 | +Copy the example environment file and fill in your details. |
| 43 | + |
| 44 | +```bash |
| 45 | +cp .env.example .env |
| 46 | +``` |
| 47 | + |
| 48 | +Open `.env` and configure the following: |
| 49 | + |
| 50 | +- `DATABASE_URL`: The SQLite connection string (default: `file:./dev.db`). |
| 51 | +- `BETTER_AUTH_SECRET`: A secure random string for encryption. You can generate one using `openssl rand -hex 32`. |
| 52 | +- `BETTER_AUTH_URL`: The base URL of your application (default: `http://localhost:3000`). |
| 53 | +- `EMAIL_USER`: Your Gmail address (for OTP delivery). |
| 54 | +- `EMAIL_PASS`: Your Gmail App Password. [How to generate an App Password](https://support.google.com/accounts/answer/185833). |
| 55 | + |
| 56 | +### 4. Database Setup |
| 57 | + |
| 58 | +Initialize your SQLite database and run migrations. |
| 59 | + |
| 60 | +```bash |
| 61 | +pnpm dlx prisma migrate dev --name init |
| 62 | +``` |
| 63 | + |
| 64 | +Generate the Prisma client |
| 65 | + |
| 66 | +```bash |
| 67 | +pnpm dlx prisma generate |
| 68 | +``` |
| 69 | + |
| 70 | +To reset the database and run the seed script: |
| 71 | + |
| 72 | +```bash |
| 73 | +pnpm prisma:reset |
| 74 | +``` |
| 75 | + |
| 76 | +### 5. Start the development server |
| 77 | + |
| 78 | +```bash |
| 79 | +pnpm dev |
| 80 | +``` |
| 81 | + |
| 82 | +Your application will be available at `http://localhost:3000`. This command also starts **Prisma Studio** automatically. |
| 83 | + |
| 84 | +### 6. How to Login |
| 85 | + |
| 86 | +Login requires an email address that already exists in the database. |
| 87 | + |
| 88 | +- **Option A: Use the seeded user** |
| 89 | + Go to `/auth` and log in with `alice@a.com`. |
| 90 | +- **Option B: Use your own email** |
| 91 | + Update `prisma/seed.ts` with your email, then run `pnpm prisma:reset` to re-seed. |
| 92 | + |
| 93 | +**To get your OTP:** |
| 94 | + |
| 95 | +- Check your configured email inbox. |
| 96 | +- **Or**, check the **Prisma Studio** tab in your browser and look in the `Verification` table. |
| 97 | + |
| 98 | +## Project Structure |
| 99 | + |
| 100 | +- `app/`: Frontend code (pages, components, assets, composables). |
| 101 | +- `server/`: Backend code (API routes, authentication logic, database utilities). |
| 102 | +- `prisma/`: Database schema, migrations, and seed scripts. |
| 103 | +- `public/`: Static assets. |
| 104 | + |
| 105 | +## License |
| 106 | + |
| 107 | +MIT |
0 commit comments