https://github.com/kinfe123/better-auth-nextjs-mongoose
https://github.com/kinfe123/better-auth-nextjs-mongoose
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/kinfe123/better-auth-nextjs-mongoose
- Owner: Kinfe123
- Created: 2025-04-22T15:26:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-26T10:32:34.000Z (about 1 year ago)
- Last Synced: 2025-04-29T05:39:23.985Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://better-auth-nextjs-mongoose.vercel.app
- Size: 143 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Better Auth Starter with Next.js and MongoDB
A complete authentication solution using Better Auth, Next.js, and MongoDB.
## Features
- 🔐 Complete authentication system
- 📧 Email/Password authentication
- 🔑 Social authentication (Google, GitHub, etc.)
- 🎯 Type-safe with TypeScript
- 🚀 Server Actions support
- 📱 Responsive design
- 🔄 Session management
- 🛡️ CSRF protection
## Prerequisites
- Node.js 18+
- pnpm (recommended) or npm
- MongoDB database
## Installation
1. **Clone the project**
```bash
git clone https://github.com/Kinfe123/better-auth-nextjs-mongoose
cd better-auth-nextjs-mongoose
```
2. **Install dependencies**
```bash
pnpm install
```
3. **Setup Env variables**
```bash
cp .env.example .env
```
Edit `.env` with your configuration:
```env
DATABASE_URL="mongodb://...."
AUTH_SECRET="your-auth-secret" # Generate with: openssl rand -base64 32
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
TWITTER_CLIENT_ID="your-twitter-client-id"
TWITTER_CLIENT_SECRET="your-twitter-client-secret"
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
```
5. **Run database migrations**
For MongoDB, we don't need to generate or migrate the schema.
6. **Run dev server**
```bash
pnpm dev
```
## Troubleshooting
Common issues and solutions:
1. **Database Connection Issues**
- Verify your DATABASE_URL in .env
- Ensure MONGO_URL is running
- Check database permissions
2. **Authentication Errors**
- Verify AUTH_SECRET is set
- Check social provider credentials
- Ensure proper CORS configuration
3. **Session Issues**
- Check cookie settings
- Verify nextCookies plugin is enabled
- Ensure proper redirect handling
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License.