A comprehensive authentication solution for Next.js applications that provides customizable authentication UI with social login options, email OTP authentication, and middleware for protected routes.
- 🔐 Built-in support for Google, GitHub, and LinkedIn authentication
- 📧 Email OTP authentication for passwordless login
- 🎨 Fully customizable with Tailwind CSS
- 🚀 CLI tool for automatic setup and configuration
- 📦 Easy to install and integrate
# Run the setup wizard
npx authcomp
Running npx authcomp
without an existing Next.js project will:
- Create a new Next.js application
- Install and configure authentication components
- Set up necessary files and environment variables
npx authcomp
The setup wizard will guide you through the installation process.
If you already have a Next.js project:
# Navigate to your project
cd your-nextjs-project
# Run the setup wizard
npx authcomp
The AuthComp setup wizard performs the following tasks:
-
Creates Authentication Routes:
- Sets up NextAuth route at
app/api/auth/[...nextauth]/route.ts
- Creates OTP authentication endpoints:
/api/auth/request-otp
/api/auth/verify-otp
- Sets up NextAuth route at
-
Adds Middleware:
- Creates a
middleware.ts
file for route protection - Configures protected routes and authentication redirects
- Creates a
-
Sets Up Utility Files:
-
utils/auth.ts
- Authentication helper functions -
utils/db.ts
- Database utilities for OTP storage -
utils/email.ts
- Email sending functionality for OTP
-
-
Configures Environment Variables:
- Creates or updates
.env
file with necessary configuration
- Creates or updates
-
Handles File Conflicts:
- If files already exist, they are renamed to
{filename}.old.{extension}
- Preserves your existing code while adding new functionality
- If files already exist, they are renamed to
AuthComp supports the following social authentication providers:
- Google - OAuth 2.0 authentication with Google accounts
- GitHub - OAuth authentication with GitHub accounts
- LinkedIn - OAuth authentication with LinkedIn accounts
Passwordless authentication using one-time passwords sent via email:
- User enters their email address
- A one-time code is sent to their email
- User enters the code to authenticate
- A session is created upon successful verification
"use client"
import { AuthLogin } from 'authcomp';
export default function LoginPage() {
return (
<AuthLogin
redirectUrl="/dashboard"
logoUrl="/your-logo.svg"
title="Welcome Back"
subtitle="Sign in to continue"
showGoogle={true}
showGithub={true}
showLinkedin={true}
showOTP={true}
buttonClassName="custom-button-class"
containerClassName="custom-container-class"
/>
);
}
Prop | Type | Default | Description |
---|---|---|---|
className |
string | "" | Additional CSS classes for the root element |
redirectUrl |
string | "/" | URL to redirect after successful login |
title |
string | "Welcome to Aganitha" | Main title text |
subtitle |
string | "You can sign in using your preferred login method" | Subtitle text |
showGoogle |
boolean | true | Toggle Google login button |
showGithub |
boolean | true | Toggle GitHub login button |
showLinkedin |
boolean | true | Toggle LinkedIn login button |
showOTP |
boolean | true | Toggle Email OTP authentication |
buttonClassName |
string | "" | Additional CSS classes for buttons |
containerClassName |
string | "" | Additional CSS classes for container |
termsUrl |
string | "#" | URL to terms of service |
privacyUrl |
string | "#" | URL to privacy policy |
logoUrl |
string | "https://www.aganitha.ai/wp-content/uploads/2023/07/logo-crop.svg" | URL to your logo |
logoClassName |
string | "" | Additional CSS classes for logo |
AuthComp includes a middleware configuration that protects routes based on authentication status:
// middleware.ts (automatically created by setup wizard)
export const config = {
matcher: ['/', '/dashboard/:path*', '/profile/:path*']
};
You can customize the protected routes by modifying the matcher
array.
Update your .env
file with your OAuth credentials:
# Authentication
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here
# Google OAuth
GOOGLE_ID=your-google-client-id
GOOGLE_SECRET=your-google-client-secret
# GitHub OAuth
GITHUB_ID=your-github-client-id
GITHUB_SECRET=your-github-client-secret
# LinkedIn OAuth
LINKEDIN_CLIENT_ID=your-linkedin-client-id
LINKEDIN_CLIENT_SECRET=your-linkedin-client-secret
# Email (for OTP)
EMAIL_SERVER=smtp://username:password@smtp.example.com:587
EMAIL_FROM=noreply@example.com
You can customize the OTP email template by modifying the utils/email.ts
file:
// Customize the email content and styling
const html = `
<div style="...">
<h1>Your Authentication Code</h1>
<p>Your one-time password is: <strong>${otp}</strong></p>
<p>This code will expire in 10 minutes.</p>
</div>
`;
By default, AuthComp uses a SQLite database for OTP storage. You can customize the database configuration in utils/db.ts
.
The AuthLogin component is built with Tailwind CSS and is fully customizable:
- Use the
className
,buttonClassName
, andcontainerClassName
props to add custom styles - The component uses a modern, responsive design that adapts to different screen sizes
- Animation effects are included for a polished user experience
- Next.js 13+ (App Router)
- React 18+
- Node.js 16+
- Tailwind CSS 3+
If you encounter file conflicts during setup, AuthComp will rename existing files to {filename}.old.{extension}
and create new ones. You can:
- Compare the old and new files to merge your changes
- Delete the
.old
files once you've verified everything works
For social login to work correctly:
- Create OAuth applications with the respective providers
- Configure the correct redirect URIs:
- Google:
https://your-domain.com/api/auth/callback/google
- GitHub:
https://your-domain.com/api/auth/callback/github
- LinkedIn:
https://your-domain.com/api/auth/callback/linkedin
- Google:
MIT