A sleek, production-ready Next.js application that enables secure user submissions through Magic Link email verification. This system ensures that every submission is backed by a verified email address, enhancing security and data integrity.
- Framework: Next.js (App Router)
- UI Architecture: Mantine UI
- Database ORM: Prisma
- Styling: Tailwind CSS & Mantine Core
- Icons: Tabler Icons
- Email Templates: React Email
- Database: PostgreSQL
- Validation: Zod
- Email Delivery: Resend
- 🎯 Secure Submissions: Users fill out a form that requires email confirmation.
- 🔗 Magic Link Verification: Secure, single-use, time-limited tokens sent via email.
- 🛡️ Token Security: High-entropy token generation with SHA-256 hashing in the database.
- ⚡ Async Processing: Non-blocking email delivery for a snappy user experience.
- 📱 Responsive Design: Fully responsive UI built with Mantine.
- ✅ Robust Validation: Client-side and server-side validation using Zod.
- Submission: User submits the form with their details and email.
- Verification: The system creates a pending submission and sends a magic link to the user's email.
- Confirmation: User clicks the link, creating a confirmed session/status, ensuring the email is valid.
Ensure you have the following installed:
- Node.js:
v18.18.0or higher - PostgreSQL: Running instance (Local or Cloud like Neon/Supabase. Both will work)
- npm
Clone the repository and install dependencies:
npm installCreate a .env file in the root directory and populate it with your credentials:
# Database connection string
DATABASE_URL="postgresql://postgres:password@localhost:5432/magic_link"
# Resend API Key for emails
RESEND_API_KEY="re_123456789"
# Sender identity for Resend (Verify this domain in Resend dashboard)
EMAIL_FROM="onboarding@yourdomain.com"
# The base URL of your application
NEXT_PUBLIC_APP_URL="http://localhost:3000"The project uses Prisma as the ORM. Follow these steps to set up your PostgreSQL database:
- Sign Up: Create a free account at Neon.tech.
- Create Project: Create a new project and database instance.
- Get Connection String:
- In the Neon console, go to the Dashboard.
- Copy the Connection Details (ensure it's the
Connection Stringformat). - It should look like:
postgresql://[user]:[password]@[neon-host]/[dbname]?sslmode=require.
- Configure
.env:- Paste the connection string into your
.envfile:DATABASE_URL="postgresql://user:password@ep-shiny-glade-123456.us-east-2.aws.neon.tech/neondb?sslmode=require"
- Paste the connection string into your
- Initialize Database:
npx prisma migrate dev --name init
If you want to run the database locally without setting up a cloud provider:
-
Start Database:
docker-compose up -d
This will start a PostgreSQL instance on port
5432. -
Configure
.env: Ensure yourDATABASE_URLmatches the Docker credentials:DATABASE_URL="postgresql://postgres:ayushManufac123@localhost:5432/magic_link"
-
Initialize Database:
npx prisma migrate dev --name init
To enable email delivery, follow these steps:
- Sign Up: Create an account at Resend.com.
- API Key: Navigate to the API Keys section and create a new key.
- Add Key: Copy the key and add it to your
.envfile asRESEND_API_KEY. - Domain Verification:
- To send emails to any recipient, you must verify your domain at resend.com/domains.
- If your domain is not verified, you can use the
resend.devtesting domain (e.g.,onboarding@resend.dev), but you can only send emails to your own account email.
- Update
.env: Once verified, updateEMAIL_FROMwith your verified email/domain.
To start the development server:
npm run devThe application will be available at http://localhost:3000.
/app/api: Backend API routes handling submissions and confirmation logic./app/confirm: Page for token verification and confirmation./app/schemas: Zod validation schemas used across client and server./app/submission: Contains the user input form./emails: React-based email templates using react-email./lib: Reusable services, Prisma client, and email utility./prisma: Database schema definition.
- Next.js Documentation
- Prisma Documentation
- Resend Documentation
- Mantine UI Components
- Tailwind CSS
- Tabler Icons
- Zod Validation
- PostgreSQL Documentation