feat: implement beautiful jsx-email templates for OTP and team invites (#196)
Co-authored-by: opencode <noreply@opencode.ai>
This commit is contained in:
47
apps/web/src/app/api/dev/email-preview/route.ts
Normal file
47
apps/web/src/app/api/dev/email-preview/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import {
|
||||
renderOtpEmail,
|
||||
renderTeamInviteEmail,
|
||||
} from "~/server/email-templates";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const type = searchParams.get("type") || "otp";
|
||||
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
return NextResponse.json({ error: "Not Found" }, { status: 404 });
|
||||
}
|
||||
|
||||
try {
|
||||
let html: string;
|
||||
|
||||
if (type === "otp") {
|
||||
html = await renderOtpEmail({
|
||||
otpCode: "ABC123",
|
||||
loginUrl: "https://app.unsend.dev/login?token=abc123",
|
||||
hostName: "Unsend",
|
||||
});
|
||||
} else if (type === "invite") {
|
||||
html = await renderTeamInviteEmail({
|
||||
teamName: "My Awesome Team",
|
||||
inviteUrl: "https://app.unsend.dev/join-team?inviteId=123",
|
||||
inviterName: "John Doe",
|
||||
role: "admin",
|
||||
});
|
||||
} else {
|
||||
return NextResponse.json({ error: "Invalid type" }, { status: 400 });
|
||||
}
|
||||
|
||||
return new NextResponse(html, {
|
||||
headers: {
|
||||
"Content-Type": "text/html",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error rendering email template:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to render email template" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user