mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 04:02:21 +02:00
🐛 Fix merge guest user into logged in user (#907)
This commit is contained in:
parent
5be17fd249
commit
7c54268b58
3 changed files with 202 additions and 201 deletions
|
@ -6,44 +6,6 @@ import { generateOtp } from "../../utils/nanoid";
|
|||
import { publicProcedure, router } from "../trpc";
|
||||
import { RegistrationTokenPayload } from "../types";
|
||||
|
||||
// assigns participants and comments created by guests to a user
|
||||
// we could have multiple guests because a login might be triggered from one device
|
||||
// and opened in another one.
|
||||
const mergeGuestsIntoUser = async (userId: string, guestIds: string[]) => {
|
||||
await prisma.poll.updateMany({
|
||||
where: {
|
||||
userId: {
|
||||
in: guestIds,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
userId: userId,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.participant.updateMany({
|
||||
where: {
|
||||
userId: {
|
||||
in: guestIds,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
userId: userId,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.comment.updateMany({
|
||||
where: {
|
||||
userId: {
|
||||
in: guestIds,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
userId: userId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const auth = router({
|
||||
// @deprecated
|
||||
requestRegistration: publicProcedure
|
||||
|
@ -107,7 +69,7 @@ export const auth = router({
|
|||
locale: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
.mutation(async ({ input }) => {
|
||||
const payload = await decryptToken<RegistrationTokenPayload>(input.token);
|
||||
|
||||
if (!payload) {
|
||||
|
@ -129,10 +91,6 @@ export const auth = router({
|
|||
},
|
||||
});
|
||||
|
||||
if (ctx.user.isGuest) {
|
||||
await mergeGuestsIntoUser(user.id, [ctx.user.id]);
|
||||
}
|
||||
|
||||
return { ok: true, user };
|
||||
}),
|
||||
getUserPermission: publicProcedure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue