From 7fa4d5cade9ef31b49152556bcf5de5a5892ef78 Mon Sep 17 00:00:00 2001 From: Ben Senescu <44480372+bensenescu@users.noreply.github.com> Date: Mon, 18 May 2026 14:24:06 -0400 Subject: [PATCH] Simplify Loops signup contact sync (#202) --- src/lib/auth.ts | 26 ++++++++++---------------- src/server/email/loops.ts | 8 ++++---- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 6316fec..98791c1 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, - upsertHostedVerifiedContact, + upsertHostedSignupContact, } from "@/server/email/loops"; const hostedBaseUrlSchema = z @@ -55,9 +55,6 @@ function createAuth() { confirmationUrl: url, }); }, - afterEmailVerification: async (user) => { - await syncHostedVerifiedContact(user, "email verification"); - }, }, socialProviders: getSocialProviders(), trustedOrigins: getTrustedOrigins(baseUrl), @@ -68,12 +65,8 @@ function createAuth() { databaseHooks: { user: { create: { - after: async (user, context) => { - if (context?.path !== "/callback/google") { - return; - } - - await syncHostedVerifiedContact(user, "Google sign up"); + after: async (user) => { + await syncHostedSignupContact(user); }, }, }, @@ -104,18 +97,19 @@ function createAuth() { let authInstance: ReturnType | null = null; -async function syncHostedVerifiedContact( - user: { id: string; email: string; name?: string | null }, - context: string, -) { +async function syncHostedSignupContact(user: { + id: string; + email: string; + name?: string | null; +}) { try { - await upsertHostedVerifiedContact({ + await upsertHostedSignupContact({ userId: user.id, email: user.email, name: user.name, }); } catch (error) { - console.error(`Failed to sync Loops profile after ${context}:`, { + console.error("Failed to sync Loops profile after user creation:", { userId: user.id, email: user.email, error, diff --git a/src/server/email/loops.ts b/src/server/email/loops.ts index d4cc397..86a3c40 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 upsertHostedVerifiedContact({ +export async function upsertHostedSignupContact({ userId, email, name, @@ -104,7 +104,7 @@ export async function upsertHostedVerifiedContact({ if (!apiKey) { console.warn( - "Skipping Loops verified contact sync: LOOPS_API_KEY is not set", + "Skipping Loops signup contact sync: LOOPS_API_KEY is not set", ); return; } @@ -129,14 +129,14 @@ export async function upsertHostedVerifiedContact({ } const errorPayload = await response.json().catch(() => null); - console.error("Loops verified contact sync error:", { + console.error("Loops signup contact sync error:", { status: response.status, email, userId, errorPayload, }); - throw new Error(`Failed to sync Loops verified contact (${response.status})`); + throw new Error(`Failed to sync Loops signup contact (${response.status})`); } export async function sendHostedVerificationEmail({