Skip to content

Commit aaf14e6

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

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
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: 5 additions & 4 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

@@ -31,7 +32,7 @@ export function createAuthenticatedPrismaClient(jwtToken?: string, role?: string
3132
}
3233

3334
if (jwtToken) {
34-
const claimsJson = JSON.stringify({ sub: jwtToken, role });
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)