Switch to version 11: modified src/app/api/waitlist/route.ts

This commit is contained in:
2026-03-06 08:25:00 +00:00
parent f4eeb48f17
commit 2f113b3b0f

View File

@@ -1,5 +1,4 @@
import { NextRequest, NextResponse } from 'next/server';
import nodemailer from 'nodemailer';
interface WaitlistEntry {
email: string;
@@ -8,16 +7,8 @@ interface WaitlistEntry {
createdAt: string;
}
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || 'smtp.gmail.com',
port: parseInt(process.env.SMTP_PORT || '587'),
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
});
// In-memory storage for demonstration
// In production, replace with actual database (MongoDB, PostgreSQL, etc.)
const waitlistEntries: WaitlistEntry[] = [];
export async function POST(request: NextRequest) {
@@ -26,17 +17,17 @@ export async function POST(request: NextRequest) {
const { email, instagram, tiktok } = body;
// Validate email
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
if (!email || typeof email !== 'string' || !email.includes('@')) {
return NextResponse.json(
{ error: 'Invalid email address' },
{ error: 'Valid email is required' },
{ status: 400 }
);
}
// Check if email already exists
// Check for duplicate email
if (waitlistEntries.some(entry => entry.email === email)) {
return NextResponse.json(
{ error: 'Email already on waitlist' },
{ error: 'Email already registered' },
{ status: 409 }
);
}
@@ -46,79 +37,50 @@ export async function POST(request: NextRequest) {
email,
instagram: instagram || undefined,
tiktok: tiktok || undefined,
createdAt: new Date().toISOString(),
createdAt: new Date().toISOString()
};
// Add to in-memory storage
waitlistEntries.push(entry);
// Send confirmation email to user
const userEmailHtml = `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<h2 style="color: #333;">Welcome to Clearance Waitlist!</h2>
<p>Hi ${email.split('@')[0]},</p>
<p>Thank you for joining the Clearance waitlist! We're excited to have you on board.</p>
<p>We'll be reaching out soon with early access to our platform. In the meantime, here's what you can expect:</p>
<ul>
<li>Exclusive early access before our public launch</li>
<li>Lifetime discounts as an early adopter</li>
<li>1-on-1 onboarding support from our team</li>
</ul>
<p>If you have any questions, feel free to reply to this email.</p>
<p>Best regards,<br/>The Clearance Team</p>
</div>
`;
// TODO: In production, save to database here
// Example for MongoDB:
// await db.collection('waitlist').insertOne(entry);
// TODO: Send confirmation email
// Example:
// await sendEmail({
// to: email,
// subject: 'Welcome to Clearance Waitlist',
// template: 'waitlist-confirmation'
// });
try {
await transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: email,
subject: 'Welcome to Clearance Waitlist - Early Access Confirmed',
html: userEmailHtml,
});
} catch (emailError) {
console.error('Error sending confirmation email:', emailError);
// Continue even if email fails - user still added to waitlist
}
// Send notification email to admin
const adminEmailHtml = `
<div style="font-family: Arial, sans-serif;">
<h2>New Waitlist Submission</h2>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Instagram:</strong> ${instagram || 'Not provided'}</p>
<p><strong>TikTok:</strong> ${tiktok || 'Not provided'}</p>
<p><strong>Submitted:</strong> ${new Date().toLocaleString()}</p>
</div>
`;
try {
await transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: process.env.ADMIN_EMAIL || process.env.SMTP_USER,
subject: `New Clearance Waitlist Submission: ${email}`,
html: adminEmailHtml,
});
} catch (emailError) {
console.error('Error sending admin notification:', emailError);
// Continue even if email fails
}
console.log('Waitlist entry created:', entry);
return NextResponse.json(
{ success: true, message: 'Successfully joined waitlist', entry },
{
success: true,
message: 'Successfully joined the waitlist',
data: entry
},
{ status: 201 }
);
} catch (error) {
console.error('Waitlist submission error:', error);
console.error('Waitlist API error:', error);
return NextResponse.json(
{ error: 'Failed to process submission' },
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
export async function GET() {
return NextResponse.json({
count: waitlistEntries.length,
entries: waitlistEntries,
});
// Optional: Get all waitlist entries (add authentication in production)
return NextResponse.json(
{
count: waitlistEntries.length,
entries: waitlistEntries
},
{ status: 200 }
);
}