Send Loops contacts after email verification (#189)

This commit is contained in:
Ben Senescu 2026-05-13 13:21:57 -04:00 committed by GitHub
parent 8773662b16
commit fa20de2126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 24 deletions

View File

@ -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) => {

View File

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