mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-29 22:27:25 +02:00
🐛 Fix account linking when using SSO (#1016)
This commit is contained in:
parent
996ca88840
commit
213152e652
2 changed files with 17 additions and 3 deletions
|
@ -222,8 +222,8 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
||||||
} else {
|
} else {
|
||||||
// merge guest user into newly logged in user
|
// merge guest user into newly logged in user
|
||||||
const session = await getServerSession(...args);
|
const session = await getServerSession(...args);
|
||||||
if (session && session.user.email === null) {
|
if (session && user.email && session.user.email === null) {
|
||||||
await mergeGuestsIntoUser(user.id, [session.user.id]);
|
await mergeGuestsIntoUser(user.email, [session.user.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
posthog?.capture({
|
posthog?.capture({
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
import { prisma } from "@rallly/database";
|
import { prisma } from "@rallly/database";
|
||||||
|
import * as Sentry from "@sentry/node";
|
||||||
|
|
||||||
export const mergeGuestsIntoUser = async (
|
export const mergeGuestsIntoUser = async (
|
||||||
userId: string,
|
email: string,
|
||||||
guestIds: 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({
|
await prisma.poll.updateMany({
|
||||||
where: {
|
where: {
|
||||||
userId: {
|
userId: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue