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 {
|
import {
|
||||||
sendHostedPasswordResetEmail,
|
sendHostedPasswordResetEmail,
|
||||||
sendHostedVerificationEmail,
|
sendHostedVerificationEmail,
|
||||||
upsertHostedSignupContact,
|
upsertHostedVerifiedContact,
|
||||||
} from "@/server/email/loops";
|
} from "@/server/email/loops";
|
||||||
|
|
||||||
const hostedBaseUrlSchema = z
|
const hostedBaseUrlSchema = z
|
||||||
@ -55,6 +55,24 @@ function createAuth() {
|
|||||||
confirmationUrl: url,
|
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),
|
trustedOrigins: getTrustedOrigins(baseUrl),
|
||||||
database: drizzleAdapter(db, {
|
database: drizzleAdapter(db, {
|
||||||
@ -62,25 +80,6 @@ function createAuth() {
|
|||||||
}),
|
}),
|
||||||
plugins: [...baseAuthConfig.plugins, tanstackStartCookies()],
|
plugins: [...baseAuthConfig.plugins, tanstackStartCookies()],
|
||||||
databaseHooks: {
|
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: {
|
session: {
|
||||||
create: {
|
create: {
|
||||||
before: async (session) => {
|
before: async (session) => {
|
||||||
|
|||||||
@ -91,7 +91,7 @@ function getContactNameParts(name: string | null | undefined) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function upsertHostedSignupContact({
|
export async function upsertHostedVerifiedContact({
|
||||||
userId,
|
userId,
|
||||||
email,
|
email,
|
||||||
name,
|
name,
|
||||||
@ -104,7 +104,7 @@ export async function upsertHostedSignupContact({
|
|||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
console.warn(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,14 +129,14 @@ export async function upsertHostedSignupContact({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const errorPayload = await response.json().catch(() => null);
|
const errorPayload = await response.json().catch(() => null);
|
||||||
console.error("Loops signup contact sync error:", {
|
console.error("Loops verified contact sync error:", {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
email,
|
email,
|
||||||
userId,
|
userId,
|
||||||
errorPayload,
|
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({
|
export async function sendHostedVerificationEmail({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user