Skip to content

Commit 033e994

Browse files
committed
chore: rename param
1 parent 5de4eee commit 033e994

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

server/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function createContext({ req }: { req: Request }) {
4848

4949
// Create an authenticated Prisma client with the user's JWT token
5050
// Pass 'authenticated' role to activate RLS policies
51-
prisma = createAuthenticatedPrismaClient(user.id, 'authenticated');
51+
prisma = createAuthenticatedPrismaClient(user.id, 'authenticated') as typeof basePrisma;
5252

5353
let ip = getClientIp(req);
5454

server/utils/prisma/prisma-client.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export const basePrisma = globalForPrisma.prisma || new PrismaClient();
77
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = basePrisma;
88

99
// Function to create an authenticated Prisma client instance
10-
export function createAuthenticatedPrismaClient(jwtToken?: string, role?: string) {
11-
// If no token, return the base client
12-
if (!jwtToken && !role) {
10+
export function createAuthenticatedPrismaClient(userId?: string, role?: string) {
11+
// User ID is required for authenticated client
12+
// It should be extracted from the JWT token
13+
if (!userId && !role) {
1314
return basePrisma;
1415
}
1516

@@ -30,8 +31,8 @@ export function createAuthenticatedPrismaClient(jwtToken?: string, role?: string
3031
await prisma.$executeRawUnsafe(`SET ROLE ${role}`);
3132
}
3233

33-
if (jwtToken) {
34-
const claimsJson = JSON.stringify({ sub: jwtToken, role });
34+
if (userId) {
35+
const claimsJson = JSON.stringify({ sub: userId, role });
3536
await prisma.$executeRawUnsafe(`SET LOCAL "request.jwt.claims" = '${claimsJson}'`);
3637
}
3738
}

0 commit comments

Comments
 (0)