Skip to content

Kinfe123/better-auth-nextjs

Repository files navigation

Better Auth Starter with Next.js and Prisma

A complete authentication solution using Better Auth, Next.js, and Prisma.

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
  • PostgreSQL database

Installation

  1. Clone the project
git clone https://github.com/Kinfe123/better-auth-nextjs
cd better-auth-nextjs
  1. Install dependencies
pnpm install
  1. Setup Env variables
cp .env.example .env

Edit .env with your configuration:

DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"
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"
  1. Run database migrations
pnpm prisma generate
pnpm prisma db push
  1. Run dev server
pnpm dev

Troubleshooting

Common issues and solutions:

  1. Database Connection Issues

    • Verify your DATABASE_URL in .env
    • Ensure PostgreSQL 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.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors