aganitha-starter-app
v3.3.0
Published
A customizable Next.js social authentication UI component with Tailwind CSS styling
Downloads
32
Maintainers
Readme
AuthComp - Next.js Authentication Component
A comprehensive authentication solution for Next.js applications that provides customizable authentication UI with social login options, email OTP authentication, LDAP authentication, and middleware for protected routes.
Features
Authentication Component
- 🔐 Built-in support for Google, GitHub, and LinkedIn authentication
- 📧 Email OTP authentication for passwordless login
- 🔑 LDAP authentication for enterprise environments
- 🎨 Fully customizable with Tailwind CSS
- 🚀 CLI tool for automatic setup and configuration
- 📦 Easy to install and integrate
Installation
# Run the setup wizard
npx authcompQuick Start Guide
Option 1: Create a New Next.js Project with 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 authcompThe setup wizard will guide you through the installation process.
Option 2: Add AuthComp to an Existing Next.js Project
If you already have a Next.js project:
# Navigate to your project
cd your-nextjs-project
# Run the setup wizard
npx authcompWhat the Setup Wizard Does
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.tsfile for route protection - Configures protected routes and authentication redirects
- Creates a
Sets Up Utility Files:
utils/auth.ts- Authentication helper functionsutils/db.ts- Database utilities for OTP storageutils/email.ts- Email sending functionality for OTP
Creates App Files:
- Creates or updates
app/layout.tsx(existing files are renamed tolayout.old.tsx) - Creates
app/login/page.tsxwith pre-configured AuthLogin component
- Creates or updates
Configures Environment Variables:
- Creates or updates
.envfile 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
Authentication Methods
Social Authentication
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
Email OTP Authentication
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
LDAP Authentication
Enterprise authentication using LDAP protocol:
- User enters their username and password
- The credentials are verified against your LDAP server
- A session is created upon successful authentication
- User is redirected to the dashboard
Using the AuthLogin Component
"use client"
import { AuthLogin } from 'authcomp';
export default function LoginPage() {
return (
j <AuthLogin
redirectUrl="/dashboard"
logoUrl="/your-logo.svg"
title="Welcome Back"
subtitle="Sign in to continue"
showGoogle={true}
showGithub={true}
showLinkedin={true}
showOTP={true}
showLDAP={true}
ldapDomain="example.com"
buttonClassName="custom-button-class"
containerClassName="custom-container-class"
/>
);
}AuthLogin Component Props
| 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 |
| showLDAP | boolean | false | Toggle LDAP authentication |
| ldapDomain | string | "" | Domain to display for LDAP login (e.g., "example.com") |
| 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 |
Route Protection with Middleware
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.
Environment Configuration
Update your .env file with your OAuth credentials and LDAP configuration:
# 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:[email protected]:587
[email protected]
# LDAP Configuration
LDAP_URI=ldap://ldap.example.com
LDAP_USER_DN=ou=people,dc=example,dc=com
LDAP_EMAIL_DOMAIN=example.comAdvanced Usage
Custom Email Templates
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>
`;Database Integration
By default, AuthComp uses a SQLite database for OTP storage. You can customize the database configuration in utils/db.ts.
Styling Customization
The AuthLogin component is built with Tailwind CSS and is fully customizable:
- Use the
className,buttonClassName, andcontainerClassNameprops 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
Requirements
- Next.js 13+ (App Router)
- React 18+
- Node.js 16+
- Tailwind CSS 3+
Troubleshooting
File Conflicts
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
.oldfiles once you've verified everything works
OAuth Configuration
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:
License
MIT
