feat(cloud): create subscribers
This commit is contained in:
@@ -6,14 +6,14 @@ import { env } from "next-runtime-env";
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import * as memberRepo from "@kan/db/repository/member.repo";
|
||||
import * as userRepo from "@kan/db/repository/user.repo";
|
||||
import { notificationClient } from "@kan/email";
|
||||
import { createSubscriber, notificationClient } from "@kan/email";
|
||||
import { createLogger } from "@kan/logger";
|
||||
import { createEmailUnsubscribeLink, createS3Client } from "@kan/shared";
|
||||
|
||||
const log = createLogger("auth");
|
||||
|
||||
import { downloadImage } from "./utils";
|
||||
|
||||
const log = createLogger("auth");
|
||||
|
||||
type BetterAuthUser = {
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
@@ -95,18 +95,26 @@ export function createDatabaseHooks(db: dbClient) {
|
||||
}
|
||||
|
||||
if (notificationClient) {
|
||||
const [firstName, ...rest] = (user.name || "")
|
||||
.split(" ")
|
||||
.filter(Boolean);
|
||||
const lastName = rest.length ? rest.join(" ") : undefined;
|
||||
|
||||
try {
|
||||
const [firstName, ...rest] = (user.name || "")
|
||||
.split(" ")
|
||||
.filter(Boolean);
|
||||
const lastName = rest.length ? rest.join(" ") : undefined;
|
||||
const avatarUrl = avatarKey
|
||||
? `${env("NEXT_PUBLIC_STORAGE_URL")}/${env("NEXT_PUBLIC_AVATAR_BUCKET_NAME")}/${avatarKey}`
|
||||
: undefined;
|
||||
|
||||
const unsubscribeUrl = await createEmailUnsubscribeLink(user.id);
|
||||
|
||||
log.info({ workflowId: "user-signup", userId: user.id, email: user.email }, "Triggering Novu workflow");
|
||||
log.info(
|
||||
{
|
||||
workflowId: "user-signup",
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
},
|
||||
"Triggering Novu workflow",
|
||||
);
|
||||
await notificationClient.trigger({
|
||||
to: {
|
||||
subscriberId: user.id,
|
||||
@@ -126,7 +134,10 @@ export function createDatabaseHooks(db: dbClient) {
|
||||
},
|
||||
workflowId: "user-signup",
|
||||
});
|
||||
log.info({ workflowId: "user-signup", userId: user.id }, "Novu workflow triggered");
|
||||
log.info(
|
||||
{ workflowId: "user-signup", userId: user.id },
|
||||
"Novu workflow triggered",
|
||||
);
|
||||
|
||||
await notificationClient.subscribers.credentials.update(
|
||||
{
|
||||
@@ -139,7 +150,22 @@ export function createDatabaseHooks(db: dbClient) {
|
||||
user.id,
|
||||
);
|
||||
} catch (error) {
|
||||
log.error({ err: error }, "Error adding user to notification client");
|
||||
log.error(
|
||||
{ err: error },
|
||||
"Error adding user to notification client",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await createSubscriber({
|
||||
email: user.email,
|
||||
externalId: user.id,
|
||||
firstName,
|
||||
lastName,
|
||||
name: user.name,
|
||||
});
|
||||
} catch (error) {
|
||||
log.error({ err: error }, "Error creating subscriber");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user