Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fix guest user not merge after creating new account (#1534)

Luke Vella74bb4140c076
diff --git a/apps/web/src/trpc/routers/auth.ts b/apps/web/src/trpc/routers/auth.ts
index 219631395..0fc6bfbe7 100644
--- a/apps/web/src/trpc/routers/auth.ts
+++ b/apps/web/src/trpc/routers/auth.ts
@@ -1,9 +1,11 @@
import { prisma } from "@rallly/database";
import { posthog } from "@rallly/posthog/server";
import { generateOtp } from "@rallly/utils/nanoid";
+import * as Sentry from "@sentry/nextjs";
import { z } from "zod";
import { isEmailBlocked } from "@/auth";
+import { mergeGuestsIntoUser } from "@/auth/merge-user";
import { getEmailClient } from "@/utils/emails";
import { createToken, decryptToken } from "@/utils/session";
@@ -86,7 +88,7 @@ export const auth = router({
locale: z.string().optional(),
}),
)
- .mutation(async ({ input }) => {
+ .mutation(async ({ input, ctx }) => {
const payload = await decryptToken<RegistrationTokenPayload>(input.token);
if (!payload) {
@@ -108,6 +110,14 @@ export const auth = router({
},
});
+ if (ctx.user && ctx.user.isGuest) {
+ try {
+ await mergeGuestsIntoUser(user.id, [ctx.user.id]);
+ } catch (err) {
+ Sentry.captureException(err);
+ }
+ }
+
posthog?.capture({
event: "register",
distinctId: user.id,