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 {
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<typeof createAuth> | 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,

View File

@ -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({