Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.5 kB ยท 49 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import { type db as defaultDb, eq } from "@openstatus/db";import { pageSubscriber } from "@openstatus/db/src/schema";import { getChannel } from "@openstatus/subscriptions";import { TRPCError } from "@trpc/server";
/** * Emails the verification link to the subscriber's own address. The token * must never be handed back to the caller, or double opt-in is meaningless. */export async function sendSubscriberVerification( db: typeof defaultDb, subscriberId: number,): Promise<void> { const subscriber = await db.query.pageSubscriber.findFirst({ where: eq(pageSubscriber.id, subscriberId), with: { page: true }, });
if (!subscriber?.email || !subscriber.token || subscriber.acceptedAt) { return; }
const verifyUrl = subscriber.page.customDomain ? `https://${subscriber.page.customDomain}/verify/${subscriber.token}` : `https://${subscriber.page.slug}.openstatus.dev/verify/${subscriber.token}`;
const channel = getChannel("email"); if (!channel) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Email channel not found", }); }
await channel.sendVerification?.( { id: subscriber.id, pageId: subscriber.pageId, pageName: subscriber.page.title, pageSlug: subscriber.page.slug, customDomain: subscriber.page.customDomain, componentIds: [], channelType: "email", email: subscriber.email, token: subscriber.token, }, verifyUrl, );}