-
Notifications
You must be signed in to change notification settings - Fork 11
Redesign mobile blocking flow and modernize email templates using React Email components #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||||||||||||
| import { DesktopReminderEmail } from "@/components/email/desktop-reminder-email"; | ||||||||||||||||||||
| import { NextRequest, NextResponse } from "next/server"; | ||||||||||||||||||||
| import { Resend } from "resend"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const resend = new Resend(process.env.RESEND_API_KEY); | ||||||||||||||||||||
| const WINDOW_MS = 60 * 60 * 1000; | ||||||||||||||||||||
| const rateLimitMap = new Map<string, { count: number; resetAt: number }>(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function isRateLimited(key: string, maxAttempts: number): boolean { | ||||||||||||||||||||
| const now = Date.now(); | ||||||||||||||||||||
| const entry = rateLimitMap.get(key); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!entry || now > entry.resetAt) { | ||||||||||||||||||||
| rateLimitMap.set(key, { count: 1, resetAt: now + WINDOW_MS }); | ||||||||||||||||||||
| if (rateLimitMap.size > 100) { | ||||||||||||||||||||
| for (const [existingKey, value] of rateLimitMap) { | ||||||||||||||||||||
| if (now > value.resetAt) { | ||||||||||||||||||||
| rateLimitMap.delete(existingKey); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (entry.count >= maxAttempts) { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| entry.count++; | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export async function POST(request: NextRequest) { | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| let body: unknown; | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| body = await request.json(); | ||||||||||||||||||||
| } catch { | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Invalid request body" }, | ||||||||||||||||||||
| { status: 400 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const { email } = body as { email?: unknown }; | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Guard that the parsed JSON body is an object before destructuring Prompt for AI agents
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!email || typeof email !== "string") { | ||||||||||||||||||||
| return NextResponse.json({ error: "Email is required" }, { status: 400 }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const normalizedEmail = email.trim().toLowerCase(); | ||||||||||||||||||||
| if (normalizedEmail.length > 254) { | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Invalid email address" }, | ||||||||||||||||||||
| { status: 400 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||||||||||||
| if (!emailRegex.test(normalizedEmail)) { | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Invalid email address" }, | ||||||||||||||||||||
| { status: 400 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const ipAddress = | ||||||||||||||||||||
| request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || | ||||||||||||||||||||
| "unknown"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( | ||||||||||||||||||||
| isRateLimited(`email:${normalizedEmail}`, 2) || | ||||||||||||||||||||
| isRateLimited(`ip:${ipAddress}`, 10) | ||||||||||||||||||||
| ) { | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Too many requests. Please try again later." }, | ||||||||||||||||||||
| { status: 429 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const { error } = await resend.emails.send({ | ||||||||||||||||||||
|
capy-ai[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This public email-sending endpoint lacks anti-abuse controls (auth/rate-limit/challenge), so it can be abused for spam. Prompt for AI agents |
||||||||||||||||||||
| from: "ThinkEx <hello@thinkex.app>", | ||||||||||||||||||||
| to: [normalizedEmail], | ||||||||||||||||||||
| subject: "Your ThinkEx link — open on desktop", | ||||||||||||||||||||
| react: DesktopReminderEmail(), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
Comment on lines
+33
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This route accepts any email address and triggers a Resend email send with no authentication check, no rate limiting, and no verification that the requester owns the target address. Anyone who discovers the endpoint can call it in a tight loop to spam arbitrary inboxes via ThinkEx's sending infrastructure, exhaust the Resend quota, and risk getting the domain flagged for abuse. At minimum, add per-IP rate limiting (e.g. with |
||||||||||||||||||||
|
|
||||||||||||||||||||
| if (error) { | ||||||||||||||||||||
| console.error("[mobile-reminder] Resend error:", error); | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Failed to send email" }, | ||||||||||||||||||||
| { status: 500 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return NextResponse.json({ success: true }); | ||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||
| console.error("[mobile-reminder] Error:", err); | ||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||
| { error: "Internal server error" }, | ||||||||||||||||||||
| { status: 500 }, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { | ||
| Body, | ||
| Button, | ||
| Container, | ||
| Head, | ||
| Heading, | ||
| Hr, | ||
| Html, | ||
| Img, | ||
| Link, | ||
| Preview, | ||
| Section, | ||
| Text, | ||
| } from "@react-email/components"; | ||
|
|
||
| export function DesktopReminderEmail() { | ||
| return ( | ||
| <Html lang="en"> | ||
| <Head /> | ||
| <Body | ||
| style={{ | ||
| backgroundColor: "#f6f9fc", | ||
| fontFamily: | ||
| 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', | ||
| margin: 0, | ||
| padding: 0, | ||
| }} | ||
| > | ||
| <Preview>Open ThinkEx on your desktop to get started</Preview> | ||
| <Container | ||
| style={{ | ||
| backgroundColor: "#ffffff", | ||
| margin: "40px auto", | ||
| maxWidth: "465px", | ||
| borderRadius: "8px", | ||
| border: "1px solid #eaeaea", | ||
| padding: "20px", | ||
| }} | ||
| > | ||
| <Section style={{ marginTop: "32px", textAlign: "center" }}> | ||
| <Img | ||
| src="https://thinkex.app/email-logo.png" | ||
| width="40" | ||
| height="40" | ||
| alt="ThinkEx" | ||
| style={{ margin: "0 auto" }} | ||
| /> | ||
| </Section> | ||
| <Heading | ||
| style={{ | ||
| fontSize: "24px", | ||
| fontWeight: "normal", | ||
| textAlign: "center", | ||
| margin: "30px 0", | ||
| color: "#000", | ||
| padding: 0, | ||
| }} | ||
| > | ||
| Continue on your desktop | ||
| </Heading> | ||
| <Text | ||
| style={{ fontSize: "14px", lineHeight: "24px", color: "#525f7f" }} | ||
| > | ||
| ThinkEx works best on a desktop or laptop computer. Click the button | ||
| below to open ThinkEx and start organizing your knowledge. | ||
| </Text> | ||
| <Section | ||
| style={{ | ||
| textAlign: "center", | ||
| marginTop: "32px", | ||
| marginBottom: "32px", | ||
| }} | ||
| > | ||
| <Button | ||
| href="https://thinkex.app" | ||
| style={{ | ||
| backgroundColor: "#000000", | ||
| borderRadius: "6px", | ||
| color: "#ffffff", | ||
| fontSize: "14px", | ||
| fontWeight: 600, | ||
| textDecoration: "none", | ||
| textAlign: "center", | ||
| padding: "12px 24px", | ||
| display: "inline-block", | ||
| }} | ||
| > | ||
| Open ThinkEx | ||
| </Button> | ||
| </Section> | ||
| <Text | ||
| style={{ fontSize: "14px", lineHeight: "24px", color: "#525f7f" }} | ||
| > | ||
| or visit:{" "} | ||
| <Link | ||
| href="https://thinkex.app" | ||
| style={{ color: "#556cd6", textDecoration: "none" }} | ||
| > | ||
| thinkex.app | ||
| </Link> | ||
| </Text> | ||
| <Hr style={{ border: "1px solid #eaeaea", margin: "26px 0" }} /> | ||
| <Text | ||
| style={{ | ||
| fontSize: "12px", | ||
| lineHeight: "24px", | ||
| color: "#8898aa", | ||
| fontStyle: "italic", | ||
| }} | ||
| > | ||
| The Workspace That Thinks With You | ||
| </Text> | ||
| <Text | ||
| style={{ fontSize: "11px", color: "#8898aa", marginTop: "12px" }} | ||
| > | ||
| © {new Date().getFullYear()} ThinkEx | ||
| </Text> | ||
| </Container> | ||
| </Body> | ||
| </Html> | ||
| ); | ||
| } | ||
|
|
||
| export default DesktopReminderEmail; |
Uh oh!
There was an error while loading. Please reload this page.