Skip to content

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

🐛 Fix account linking when using SSO (#1016)

Luke Vella213152e652ac
diff --git a/apps/web/src/utils/auth.ts b/apps/web/src/utils/auth.ts
index ca05d809c..00831159d 100644
--- a/apps/web/src/utils/auth.ts
+++ b/apps/web/src/utils/auth.ts
@@ -222,8 +222,8 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
} else {
// merge guest user into newly logged in user
const session = await getServerSession(...args);
- if (session && session.user.email === null) {
- await mergeGuestsIntoUser(user.id, [session.user.id]);
+ if (session && user.email && session.user.email === null) {
+ await mergeGuestsIntoUser(user.email, [session.user.id]);
}
posthog?.capture({
diff --git a/apps/web/src/utils/auth/merge-user.ts b/apps/web/src/utils/auth/merge-user.ts
index cf560fd43..f7cc4da82 100644
--- a/apps/web/src/utils/auth/merge-user.ts
+++ b/apps/web/src/utils/auth/merge-user.ts
@@ -1,9 +1,23 @@
import { prisma } from "@rallly/database";
+import * as Sentry from "@sentry/node";
export const mergeGuestsIntoUser = async (
- userId: string,
+ email: string,
guestIds: string[],
) => {
+ const user = await prisma.user.findUnique({
+ where: {
+ email: email,
+ },
+ });
+
+ const userId = user?.id;
+
+ if (!userId) {
+ Sentry.captureMessage("Could not find user to merge guests into.");
+ return;
+ }
+
await prisma.poll.updateMany({
where: {
userId: {