Create linked prisma model on sign up?

I'm trying to set up a hook to create a new linked prisma model to the user when the user signs up but I can't seem to get it to work. I've seen a few examples where others are creating new organizations so I used those for reference, but it doesn't seem to be working. Any help would be appreciated! I have added the new field to the user that I want to capture and use to transfer over. I know this is working because I can see the new field save to user, but I want to use that new field to create the new relationship with. Here's my code:
hooks: {
after: createAuthMiddleware(async (ctx) => {
try {
if (ctx.path === "/sign-up") {
const newUser = ctx.context.newSession?.user;

if (!newUser) {
throw new Error("User not found");
}

await prisma.user.update({
where: { id: newUser.id },
data: {
profile: {
create: {
accountType: newUser.accountType,
},
},
},
});
}
} catch (error) {
console.error(error);
}
}),
},
hooks: {
after: createAuthMiddleware(async (ctx) => {
try {
if (ctx.path === "/sign-up") {
const newUser = ctx.context.newSession?.user;

if (!newUser) {
throw new Error("User not found");
}

await prisma.user.update({
where: { id: newUser.id },
data: {
profile: {
create: {
accountType: newUser.accountType,
},
},
},
});
}
} catch (error) {
console.error(error);
}
}),
},
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?