Skip to content

Commit

Permalink
🐛 Fix guest user not merge after creating new account (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored Jan 31, 2025
1 parent d1e9f71 commit 74bb414
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/web/src/trpc/routers/auth.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 74bb414

Please sign in to comment.