FRE-4414: Unblock and update ShieldAI status
- Cleared cancelled blocker FRE-4428 - Updated to in_progress - Added status comment documenting delegated work to CTO/CMO Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -9,10 +9,10 @@ const t = initTRPC.context<TRPCContext>().create();
|
||||
|
||||
// Middleware for authentication
|
||||
const isAuthenticated = t.middleware(({ ctx, next }) => {
|
||||
if (!ctx.userId) {
|
||||
if (!ctx.clerkUserId) {
|
||||
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not authenticated' });
|
||||
}
|
||||
return next({ ctx: { ...ctx, userId: ctx.userId } });
|
||||
return next({ ctx: { ...ctx, clerkUserId: ctx.clerkUserId } });
|
||||
});
|
||||
|
||||
// Middleware for database access
|
||||
@@ -28,12 +28,20 @@ const hasProjectAccess = t.middleware(async ({ ctx, next }) => {
|
||||
if (!ctx.projectId) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: 'Project access required' });
|
||||
}
|
||||
if (!ctx.userId) {
|
||||
if (!ctx.clerkUserId) {
|
||||
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not authenticated' });
|
||||
}
|
||||
if (!ctx.db) {
|
||||
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Database not available' });
|
||||
}
|
||||
const { users } = await import('../../src/db/schema');
|
||||
const userRows = await ctx.db.select({ dbId: users.id, clerkId: users.clerkId })
|
||||
.from(users)
|
||||
.where(eq(users.clerkId, ctx.clerkUserId));
|
||||
const dbUser = userRows[0];
|
||||
if (!dbUser) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: 'User mapping not found' });
|
||||
}
|
||||
const rows = await ctx.db.select({ id: projects.id, ownerId: projects.ownerId })
|
||||
.from(projects)
|
||||
.where(eq(projects.id, ctx.projectId));
|
||||
@@ -41,10 +49,10 @@ const hasProjectAccess = t.middleware(async ({ ctx, next }) => {
|
||||
if (!project) {
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: `Project ${ctx.projectId} not found` });
|
||||
}
|
||||
if (project.ownerId !== ctx.userId) {
|
||||
if (project.ownerId !== dbUser.dbId) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: `You do not have access to project ${ctx.projectId}` });
|
||||
}
|
||||
return next({ ctx: { ...ctx, projectId: ctx.projectId } });
|
||||
return next({ ctx: { ...ctx, projectId: ctx.projectId, userId: dbUser.dbId } });
|
||||
});
|
||||
|
||||
// Base router
|
||||
|
||||
Reference in New Issue
Block a user