What are you using for authorization?

Hey, so I got started on the "full" T3 stack recently and I'm wondering what everyone here is using for authorization?
4 Replies
shiroyasha9
shiroyasha9•2y ago
Howdy! Do you mean which providers do we use, or the library in general? (because it's next auth for the later)
HonestCode
HonestCode•2y ago
im curious about this aswell, react native solution in particular
jonasmerlin
jonasmerlin•2y ago
I'm talking about authorization, not authentication 😄
shiroyasha9
shiroyasha9•2y ago
oh my bad lol This is a particular code that I wrote for authorization in a project
export const enforceUserIsAuthorized = async (
userId: string,
teensyId: number,
) => {
try {
const teensy = await prisma.teensy.findUnique({
where: { id: teensyId },
});
if (!teensy || teensy.ownerId !== userId) {
throw new Error("Not authorized");
}
} catch (e) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
};
export const enforceUserIsAuthorized = async (
userId: string,
teensyId: number,
) => {
try {
const teensy = await prisma.teensy.findUnique({
where: { id: teensyId },
});
if (!teensy || teensy.ownerId !== userId) {
throw new Error("Not authorized");
}
} catch (e) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
};
I use this as an await call if I want a procedure to check if user is authorized, and pass the userId from the context at server side
await enforceUserIsAuthorized(ctx.session.user.id, input.id);
await enforceUserIsAuthorized(ctx.session.user.id, input.id);
haven't really tested this for RN, but definitely sounds like something I should test out on my stack
Want results from more Discord servers?
Add your server