add fields to session
I'm using Prisma and doing an initial query to get
orgId
from my User table before almost every query/mutation. Ideally I'd just like orgId to be included in my ctx/session so I can access it directly similar to ctx.session.user.id
. I have orgId in my Session table already, but not sure how to map that to context/session.
an example of a typical query:
getLowInvWarnings: protectedProcedure.query(async ({ ctx }) => {
const orgID = await ctx.prisma.user.findUnique({
where: {
id: ctx.session.user.id,
},
select: {
orgID: true,
},
});
if (!orgID?.orgID) return;
const lowInvGreenCoffee = await ctx.prisma.greenCoffee.findMany({
where: {
orgId: orgID?.orgID,
},
select: {
id: true,
name: true,
weight: true,
minInventory: true,
},
});
This is probably a noob question, but want to see other folk's thoughts on how they would handle this.
Thanks!2 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
you are absolutely right! This is exactly what I needed, thank you!!!!