Send Loops contacts after email verification (#189)
This commit is contained in:
parent
8773662b16
commit
fa20de2126
@ -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) => {
|
||||
|
||||
@ -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({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user