{"id":30258802,"url":"https://github.com/codestackr/better-auth-mongodb","last_synced_at":"2025-10-30T05:32:05.692Z","repository":{"id":309597873,"uuid":"1036768115","full_name":"codeSTACKr/better-auth-mongodb","owner":"codeSTACKr","description":"A modern authentication template built with Next.js, Better Auth, and MongoDB. Features user registration, authentication, authorization, and a full-featured todo application demonstrating CRUD operations with MongoDB.","archived":false,"fork":false,"pushed_at":"2025-08-12T19:20:50.000Z","size":113,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T20:23:35.784Z","etag":null,"topics":["better-auth","javascript","mongodb","nextjs","react","reactjs","shadcn","shadcn-ui","tailwind","tailwind-css","tailwindcss","typescript"],"latest_commit_sha":null,"homepage":"https://docs.mongodb.com/?utm_campaign=devrel\u0026utm_source=third-party-content\u0026utm_medium=cta\u0026utm_content=github-better-auth-mongodb\u0026utm_term=jesse.hall","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeSTACKr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-12T14:54:05.000Z","updated_at":"2025-08-12T19:25:54.000Z","dependencies_parsed_at":"2025-08-12T20:35:23.095Z","dependency_job_id":null,"html_url":"https://github.com/codeSTACKr/better-auth-mongodb","commit_stats":null,"previous_names":["codestackr/better-auth-mongodb"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/codeSTACKr/better-auth-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeSTACKr%2Fbetter-auth-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeSTACKr%2Fbetter-auth-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeSTACKr%2Fbetter-auth-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeSTACKr%2Fbetter-auth-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeSTACKr","download_url":"https://codeload.github.com/codeSTACKr/better-auth-mongodb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeSTACKr%2Fbetter-auth-mongodb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270602463,"owners_count":24614264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["better-auth","javascript","mongodb","nextjs","react","reactjs","shadcn","shadcn-ui","tailwind","tailwind-css","tailwindcss","typescript"],"created_at":"2025-08-15T17:16:28.729Z","updated_at":"2025-10-30T05:32:05.586Z","avatar_url":"https://github.com/codeSTACKr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Better Auth MongoDB Demo\n\nA modern authentication template built with Next.js, Better Auth, and MongoDB. Features user registration, authentication, and a full-featured todo application demonstrating CRUD operations with MongoDB.\n\n## Features\n\n- 🔐 **Authentication**: Complete auth system with Better Auth\n  - Email/password registration and login\n  - GitHub OAuth support (configurable)\n  - Session management with middleware protection\n- 🍃 **MongoDB Integration**: Full MongoDB adapter for Better Auth\n  - User and session storage\n  - Todo CRUD operations\n- 🎨 **Modern UI**: Built with shadcn/ui components\n  - Responsive design\n  - Dark/light theme support\n  - Beautiful, accessible components\n- ✅ **Todo Management**: Complete todo application\n  - Create, read, update, delete todos\n  - Toggle completion status\n  - User-specific todos with authentication\n\n## Tech Stack\n\n- **Framework**: Next.js 15 with App Router\n- **Authentication**: Better Auth with MongoDB adapter\n- **Database**: MongoDB\n- **Styling**: TailwindCSS + shadcn/ui\n- **TypeScript**: Full type safety\n- **UI Components**: Radix UI + Lucide icons\n\n## Getting Started\n\n### Prerequisites\n\n- Node.js 18+ \n- MongoDB database (local or Atlas)\n\n### Environment Variables\n\nCreate a `.env.local` file in the root directory (see `.env.example` for reference):\n\n```bash\n# MongoDB Configuration\nMONGODB_URI=mongodb://localhost:27017\nMONGODB_DB=better-auth\n\n# Better Auth Configuration\nNEXT_PUBLIC_AUTH_URL=http://localhost:3000\nBETTER_AUTH_SECRET=your-secure-secret-key-here-minimum-32-characters\n\n# GitHub OAuth (required for social login)\nGITHUB_CLIENT_ID=your-github-client-id\nGITHUB_CLIENT_SECRET=your-github-client-secret\n```\n\n### Installation \u0026 Development\n\n1. Clone the repository and install dependencies:\n```bash\nnpm install\n```\n\n2. Start the development server:\n```bash\nnpm run dev\n```\n\n3. Open [http://localhost:3000](http://localhost:3000) in your browser\n\n## Project Structure\n\n```\nsrc/\n├── app/                    # Next.js App Router\n│   ├── api/auth/          # Better Auth API routes\n│   ├── auth/              # Authentication pages (login/signup)\n│   ├── todos/             # Todo management page\n│   └── page.tsx           # Landing page\n├── components/            # React components\n│   ├── auth/              # Authentication components\n│   └── ui/                # shadcn/ui components\n├── hooks/                 # Custom React hooks\n├── lib/                   # Core utilities and configuration\n│   ├── auth.ts           # Better Auth configuration\n│   ├── auth-client.ts    # Client-side auth hooks\n│   ├── auth-server.ts    # Server-side auth utilities\n│   ├── actions.ts        # Server actions with auth checks\n│   ├── mongodb.ts        # MongoDB client setup\n│   ├── env.ts            # Environment variable validation\n│   ├── types.ts          # TypeScript definitions\n│   └── utils.ts          # Utility functions (cn, etc.)\n└── middleware.ts          # Route protection middleware\ncomponents.json            # shadcn/ui configuration\n.env.example              # Environment variables template\n```\n\n## Authentication Flow\n\n1. **Landing Page**: Welcome screen that redirects authenticated users to todos\n2. **Registration/Login**: Forms with validation and error handling\n3. **Todo Dashboard**: Protected route at `/todos` with user profile and todo management\n4. **Session Management**: Automatic session handling with Better Auth and middleware protection\n\n## API Routes\n\n- `POST /api/auth/*` - Better Auth endpoints (handled automatically)\n\nTodo operations are handled via server actions in `src/lib/actions.ts` instead of API routes:\n- `getTodos()` - Fetch user's todos\n- `createTodo()` - Create new todo  \n- `updateTodo()` - Update todo\n- `deleteTodo()` - Delete todo\n\n## MongoDB Schema\n\nThe app uses Better Auth's automatic schema creation for users and sessions, plus custom collections for todos with proper user relationships.\n\n## Commands\n\n- `npm run dev` - Start development server with Turbopack\n- `npm run build` - Build for production\n- `npm run start` - Start production server\n- `npm run lint` - Run ESLint\n\n## Learn More\n\n- [Better Auth Documentation](https://better-auth.com)\n- [Next.js Documentation](https://nextjs.org/docs)\n- [MongoDB Documentation](https://docs.mongodb.com/?utm_campaign=devrel\u0026utm_source=third-party-content\u0026utm_medium=cta\u0026utm_content=github-better-auth-mongodb\u0026utm_term=jesse.hall)\n- [shadcn/ui Documentation](https://ui.shadcn.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodestackr%2Fbetter-auth-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodestackr%2Fbetter-auth-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodestackr%2Fbetter-auth-mongodb/lists"}