Auth 2FA
A secure, full-stack two-factor authentication component with email verification, progressive UI, and seamless Next.js server actions integration.
Two-Factor Authentication Form
A comprehensive, secure two-factor authentication component that provides email-based verification with a beautiful, progressive user interface. Features real-time validation, automatic code expiration, and seamless integration with Next.js server actions.

Installation
Install the component using the AxionsJS CLI:
Configure your environment variables in .env
:
Set up Prisma schema and push to database:
The component includes complete database models for users, two-factor tokens, and confirmations. Email templates and server actions are pre-configured and ready to use.
Database Schema
Add the following models to your schema.prisma
file:
Run npx prisma db push
after adding the schema to apply changes to your database.
Usage
Import and use the TwoFactorForm component:
Key Features
Progressive UI
Two-step interface with smooth transitions and progress indicators
Email Verification
Secure 6-digit code delivery with beautiful email templates
Auto Expiration
Tokens automatically expire after 5 minutes for enhanced security
Real-time Validation
Instant feedback with Zod schema validation and error handling
Resend Functionality
Easy code resending with rate limiting and user feedback
Accessibility
Full keyboard navigation and screen reader support
Component Props
Prop | Type | Default |
---|---|---|
onSuccess | (email: string) => void | undefined |
onError | (error: string) => void | undefined |
title | string | "Two-Factor Authentication" |
description | string | "Secure your account with an additional layer of protection" |
className | string | "" |
Server Actions
The component utilizes Next.js server actions for secure backend operations:
Features:
- Email validation with Zod schema
- Automatic token cleanup (removes old tokens)
- Secure 6-digit code generation
- Professional email template delivery
Email Templates
The component includes a beautiful, responsive email template:
Email Features:
- Responsive design for all devices
- Professional gradient styling
- Clear, large verification code display
- Security warnings and instructions
- Plain text fallback for accessibility
Security Features
The Two-Factor Authentication Form implements multiple security layers:
- Token Expiration: All codes expire after 5 minutes
- Single Use: Tokens are deleted after successful verification
- Rate Limiting: Prevents spam and abuse (configurable)
- Secure Generation: Uses Node.js crypto for token generation
- Input Validation: Comprehensive validation with Zod schemas
- SQL Injection Protection: Prisma provides built-in protection
Always use HTTPS in production and ensure your email provider supports secure authentication.
Conclusion
The Two-Factor
Authentication Form provides a complete, production-ready
solution for adding email-based 2FA to your Next.js applications. With its progressive UI, comprehensive security features, and seamless server actions integration, it delivers both excellent user experience and robust security protection.