A demonstration of AuthJS v5 in Next.js with multiple authentication providers, database integration, and protected routes.
- Next.js - React framework for production
- TypeScript - Type safety
- NextAuth.js - Authentication
- Drizzle ORM - Database ORM
- Tailwind CSS, Shadcn - Styling
- Zod - Schema validation on runtime
├── src/
│ ├── app/
│ ├── components/
│ ├── db/
│ ├── lib/
│ ├── auth.ts
│ └── middleware.ts
├── public/
├── .env.local
├── auth.config.ts
├── drizzle.config.ts
└── tailwind.config.ts
- User authentication with NextAuth.js
- Support for multiple auth providers:
- GitHub
- Credentials (username/password)
- Type-safe database queries with Drizzle ORM
- Responsive UI with Tailwind CSS
- Form validation using Zod schemas
Before you begin, ensure you have the following installed:
- Node.js (v14.x or higher): Required to run the server and client applications.
- npm (v6.x or higher): Package managers to install dependencies.
- PostgreSQL: The database used for storing user information. Ensure you have it installed and set up locally or have access to a remote PostgreSQL instance.
You will also need:
- A Google Cloud Platform account for Google OAuth
- A GitHub account for GitHub OAuth
-
Clone the repository
git clone https://github.com/JuhilSavani/authjs-impl.git cd authjs-impl
-
Install dependencies:
npm install
-
Create a
.env.local
file with required environment variables:AUTH_SECRET="your_auth_secret_here" DATABASE_URL="postgres://username:password@host:port/database" GITHUB_CLIENT_ID="your_github_client_id" GITHUB_CLIENT_SECRET="your_github_client_secret" GOOGLE_CLIENT_ID="your_google_client_id" GOOGLE_CLIENT_SECRET="your_google_client_secret"
-
Database setup:
This project uses PostgreSQL as its database management system. Follow the steps below to set up the database.- Open the terminal on your system.
- Run the following Command to create a database.
psql -U postgres -c "CREATE DATABASE authjs_impl_db;"
If you encounter a command not found error for psql, you may need to add PostgreSQL to your system’s PATH environment variable.
-
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser
page.tsx
- Home page component- Authentication routes:
- API routes for handling auth requests
- Protected routes using middleware
- Database models for user data
- Reusable UI components
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
Happy Contributing, 🚀!