From fa20de2126e688e83ba99d8777bb60285e60e0f7 Mon Sep 17 00:00:00 2001 From: Ben Senescu <44480372+bensenescu@users.noreply.github.com> Date: Wed, 13 May 2026 13:21:57 -0400 Subject: [PATCH] Send Loops contacts after email verification (#189) --- src/lib/auth.ts | 39 +++++++++++++++++++-------------------- src/server/email/loops.ts | 8 ++++---- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index eb0ba2b..b28b756 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -9,7 +9,7 @@ import { getOrCreateDefaultHostedOrganization } from "@/server/auth/default-host import { sendHostedPasswordResetEmail, sendHostedVerificationEmail, - upsertHostedSignupContact, + upsertHostedVerifiedContact, } from "@/server/email/loops"; const hostedBaseUrlSchema = z @@ -55,6 +55,24 @@ function createAuth() { confirmationUrl: url, }); }, + afterEmailVerification: async (user) => { + try { + await upsertHostedVerifiedContact({ + userId: user.id, + email: user.email, + name: user.name, + }); + } catch (error) { + console.error( + "Failed to sync Loops profile after verification:", + { + userId: user.id, + email: user.email, + error, + }, + ); + } + }, }, trustedOrigins: getTrustedOrigins(baseUrl), database: drizzleAdapter(db, { @@ -62,25 +80,6 @@ function createAuth() { }), plugins: [...baseAuthConfig.plugins, tanstackStartCookies()], databaseHooks: { - user: { - create: { - after: async (user) => { - try { - await upsertHostedSignupContact({ - userId: user.id, - email: user.email, - name: user.name, - }); - } catch (error) { - console.error("Failed to create Loops profile for signup:", { - userId: user.id, - email: user.email, - error, - }); - } - }, - }, - }, session: { create: { before: async (session) => { diff --git a/src/server/email/loops.ts b/src/server/email/loops.ts index 86a3c40..d4cc397 100644 --- a/src/server/email/loops.ts +++ b/src/server/email/loops.ts @@ -91,7 +91,7 @@ function getContactNameParts(name: string | null | undefined) { }; } -export async function upsertHostedSignupContact({ +export async function upsertHostedVerifiedContact({ userId, email, name, @@ -104,7 +104,7 @@ export async function upsertHostedSignupContact({ if (!apiKey) { console.warn( - "Skipping Loops signup contact sync: LOOPS_API_KEY is not set", + "Skipping Loops verified contact sync: LOOPS_API_KEY is not set", ); return; } @@ -129,14 +129,14 @@ export async function upsertHostedSignupContact({ } const errorPayload = await response.json().catch(() => null); - console.error("Loops signup contact sync error:", { + console.error("Loops verified contact sync error:", { status: response.status, email, userId, errorPayload, }); - throw new Error(`Failed to sync Loops signup contact (${response.status})`); + throw new Error(`Failed to sync Loops verified contact (${response.status})`); } export async function sendHostedVerificationEmail({