Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
📈 Track email change (#1918)
Luke Vella7b2d77501e35
diff --git a/apps/web/src/app/api/user/verify-email-change/route.ts b/apps/web/src/app/api/user/verify-email-change/route.tsindex dccdd1e2b..9b5c552e6 100644--- a/apps/web/src/app/api/user/verify-email-change/route.ts+++ b/apps/web/src/app/api/user/verify-email-change/route.ts@@ -1,10 +1,11 @@import { stripe } from "@rallly/billing";import { prisma } from "@rallly/database";+import { posthog } from "@rallly/posthog/server";import * as Sentry from "@sentry/nextjs";+import { waitUntil } from "@vercel/functions";import { cookies } from "next/headers";import type { NextRequest } from "next/server";import { NextResponse } from "next/server";-import { auth } from "@/next-auth";import { decryptToken } from "@/utils/session";@@ -40,6 +41,16 @@ const handleEmailChange = async (token: string) => {},});+ posthog?.capture({+ event: "account_email_change_complete",+ distinctId: payload.userId,+ properties: {+ $set: {+ email: payload.toEmail,+ },+ },+ });+try {if (user.customerId) {await stripe.customers.update(user.customerId, {@@ -52,6 +63,10 @@ const handleEmailChange = async (token: string) => {await setEmailChangeCookie("success");+ if (posthog) {+ waitUntil(posthog.flush());+ }+return true;};diff --git a/apps/web/src/trpc/routers/user.ts b/apps/web/src/trpc/routers/user.tsindex 0301cfcd6..f0e3b7afb 100644--- a/apps/web/src/trpc/routers/user.ts+++ b/apps/web/src/trpc/routers/user.ts@@ -1,4 +1,5 @@import { prisma } from "@rallly/database";+import { posthog } from "@rallly/posthog/server";import { absoluteUrl } from "@rallly/utils/absolute-url";import { TRPCError } from "@trpc/server";import { z } from "zod";@@ -139,6 +140,15 @@ export const user = router({},});+ posthog?.capture({+ event: "account_email_change_request",+ distinctId: ctx.user.id,+ properties: {+ toEmail: input.email,+ fromEmail: currentUser.email,+ },+ });+return { success: true as const };}),getAvatarUploadUrl: privateProcedure