Simplify Loops signup contact sync (#202)

This commit is contained in:
Ben Senescu 2026-05-18 14:24:06 -04:00 committed by GitHub
parent a8124a07b5
commit 7fa4d5cade
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 20 deletions

View File

@ -9,7 +9,7 @@ import { getOrCreateDefaultHostedOrganization } from "@/server/auth/default-host
import { import {
sendHostedPasswordResetEmail, sendHostedPasswordResetEmail,
sendHostedVerificationEmail, sendHostedVerificationEmail,
upsertHostedVerifiedContact, upsertHostedSignupContact,
} from "@/server/email/loops"; } from "@/server/email/loops";
const hostedBaseUrlSchema = z const hostedBaseUrlSchema = z
@ -55,9 +55,6 @@ function createAuth() {
confirmationUrl: url, confirmationUrl: url,
}); });
}, },
afterEmailVerification: async (user) => {
await syncHostedVerifiedContact(user, "email verification");
},
}, },
socialProviders: getSocialProviders(), socialProviders: getSocialProviders(),
trustedOrigins: getTrustedOrigins(baseUrl), trustedOrigins: getTrustedOrigins(baseUrl),
@ -68,12 +65,8 @@ function createAuth() {
databaseHooks: { databaseHooks: {
user: { user: {
create: { create: {
after: async (user, context) => { after: async (user) => {
if (context?.path !== "/callback/google") { await syncHostedSignupContact(user);
return;
}
await syncHostedVerifiedContact(user, "Google sign up");
}, },
}, },
}, },
@ -104,18 +97,19 @@ function createAuth() {
let authInstance: ReturnType<typeof createAuth> | null = null; let authInstance: ReturnType<typeof createAuth> | null = null;
async function syncHostedVerifiedContact( async function syncHostedSignupContact(user: {
user: { id: string; email: string; name?: string | null }, id: string;
context: string, email: string;
) { name?: string | null;
}) {
try { try {
await upsertHostedVerifiedContact({ await upsertHostedSignupContact({
userId: user.id, userId: user.id,
email: user.email, email: user.email,
name: user.name, name: user.name,
}); });
} catch (error) { } catch (error) {
console.error(`Failed to sync Loops profile after ${context}:`, { console.error("Failed to sync Loops profile after user creation:", {
userId: user.id, userId: user.id,
email: user.email, email: user.email,
error, error,

View File

@ -91,7 +91,7 @@ function getContactNameParts(name: string | null | undefined) {
}; };
} }
export async function upsertHostedVerifiedContact({ export async function upsertHostedSignupContact({
userId, userId,
email, email,
name, name,
@ -104,7 +104,7 @@ export async function upsertHostedVerifiedContact({
if (!apiKey) { if (!apiKey) {
console.warn( 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; return;
} }
@ -129,14 +129,14 @@ export async function upsertHostedVerifiedContact({
} }
const errorPayload = await response.json().catch(() => null); const errorPayload = await response.json().catch(() => null);
console.error("Loops verified contact sync error:", { console.error("Loops signup contact sync error:", {
status: response.status, status: response.status,
email, email,
userId, userId,
errorPayload, 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({ export async function sendHostedVerificationEmail({