Add explicit contact opt-in before Resend list signup
This commit is contained in:
@@ -85,7 +85,7 @@ function contactRateLimit(req, res, next) {
|
||||
|
||||
app.post('/api/contact', contactRateLimit, async (req, res) => {
|
||||
try {
|
||||
const { name, email, message, _honey } = req.body ?? {}
|
||||
const { name, email, message, subscribe, _honey } = req.body ?? {}
|
||||
|
||||
// Honeypot — silently discard if filled by a bot
|
||||
if (_honey) {
|
||||
@@ -121,34 +121,37 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
|
||||
})
|
||||
|
||||
const resend = new Resend(process.env.RESEND_API_KEY)
|
||||
const { firstName, lastName } = splitName(trimmedName)
|
||||
const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY)
|
||||
|
||||
try {
|
||||
const { error: contactError } = await contactResend.contacts.create({
|
||||
email: trimmedEmail,
|
||||
firstName,
|
||||
lastName,
|
||||
unsubscribed: false,
|
||||
...(process.env.RESEND_SEGMENT_ID
|
||||
? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] }
|
||||
: {}),
|
||||
})
|
||||
if (subscribe === true) {
|
||||
const { firstName, lastName } = splitName(trimmedName)
|
||||
const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY)
|
||||
|
||||
if (contactError) {
|
||||
const { error: updateError } = await contactResend.contacts.update({
|
||||
try {
|
||||
const { error: contactError } = await contactResend.contacts.create({
|
||||
email: trimmedEmail,
|
||||
firstName,
|
||||
lastName,
|
||||
unsubscribed: false,
|
||||
...(process.env.RESEND_SEGMENT_ID
|
||||
? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] }
|
||||
: {}),
|
||||
})
|
||||
|
||||
if (updateError) {
|
||||
console.error('[contact] contact sync error:', updateError)
|
||||
if (contactError) {
|
||||
const { error: updateError } = await contactResend.contacts.update({
|
||||
email: trimmedEmail,
|
||||
firstName,
|
||||
lastName,
|
||||
unsubscribed: false,
|
||||
})
|
||||
|
||||
if (updateError) {
|
||||
console.error('[contact] contact sync error:', updateError)
|
||||
}
|
||||
}
|
||||
} catch (contactSyncErr) {
|
||||
console.error('[contact] contact sync exception:', contactSyncErr)
|
||||
}
|
||||
} catch (contactSyncErr) {
|
||||
console.error('[contact] contact sync exception:', contactSyncErr)
|
||||
}
|
||||
|
||||
const { error } = await resend.emails.send({
|
||||
|
||||
Reference in New Issue
Block a user