Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const useStartProject = () => {
await apiUtils.project.createRequest.getPendingRequest.invalidate({ projectId: editorEngine.projectId });
},
});
const { mutateAsync: trackProjectAccess } = api.project.trackAccess.useMutation({
onSuccess: () => {
apiUtils.project.list.invalidate();
},
});
const [projectReadyState, setProjectReadyState] = useState<ProjectReadyState>({
canvas: false,
conversations: false,
Expand All @@ -54,6 +59,10 @@ export const useStartProject = () => {
}
}, [sandbox.session.isConnecting]);

useEffect(() => {
trackProjectAccess({ projectId: editorEngine.projectId }).catch(console.error);
}, [editorEngine.projectId, trackProjectAccess]);
Comment on lines +62 to +64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fire-and-forget error handling silences all failures.

The .catch(console.error) pattern silently swallows errors from the tracking mutation. While this may be acceptable for non-critical tracking, consider whether authorization failures, network errors, or invalid project IDs should be handled more explicitly (e.g., with a toast notification for unexpected errors).


useEffect(() => {
if (tabState === 'reactivated') {
sandbox.session.reconnect(editorEngine.projectId, user?.id);
Expand Down
26 changes: 26 additions & 0 deletions apps/web/client/src/server/api/routers/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { env } from '@/env';
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
import { TRPCError } from '@trpc/server';
import { trackEvent } from '@/utils/analytics/server';
import FirecrawlApp from '@mendable/firecrawl-js';
import { initModel } from '@onlook/ai';
Expand Down Expand Up @@ -422,4 +423,29 @@ export const projectRouter = createTRPCRouter({

return { success: true, tags: newTags };
}),

trackAccess: protectedProcedure
.input(z.object({ projectId: z.string().uuid() }))
.mutation(async ({ ctx, input }) => {
// Check if user has access to this project
const membership = await ctx.db.query.userProjects.findFirst({
where: and(
eq(userProjects.userId, ctx.user.id),
eq(userProjects.projectId, input.projectId),
),
});

if (!membership) {
throw new TRPCError({
code: 'FORBIDDEN',
message: 'You do not have access to this project'
});
}

await ctx.db.update(projects).set({
updatedAt: new Date(),
}).where(eq(projects.id, input.projectId));

return { success: true };
}),
});
4 changes: 2 additions & 2 deletions apps/web/client/src/server/api/routers/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const userRouter = createTRPCRouter({
lastName: user.lastName ?? lastName,
displayName: user.displayName ?? displayName,
email: user.email ?? authUser.email,
avatarUrl: user.avatarUrl ?? authUser.user_metadata.avatarUrl,
avatarUrl: user.avatarUrl ?? authUser.user_metadata.avatar_url,
}) : null;
return userData;
}),
Expand Down Expand Up @@ -56,7 +56,7 @@ export const userRouter = createTRPCRouter({
lastName: input.lastName ?? lastName,
displayName: input.displayName ?? displayName,
email: input.email ?? authUser.email,
avatarUrl: input.avatarUrl ?? authUser.user_metadata.avatarUrl,
avatarUrl: input.avatarUrl ?? authUser.user_metadata.avatar_url,
};

const [user] = await ctx.db
Expand Down
Loading