fix: revert client-side filtering, trust backend project scoping

listProjects already returns only the projects a user has access to
based on their org/project roles. Client-side filtering was wrong.
Keep graceful degradation on listPlatforms so a flaky call can't
crash the entire org page.
This commit is contained in:
harsh mahajan
2026-05-29 12:42:10 +05:30
parent 88763df760
commit f2efc378db
@@ -32,28 +32,24 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
? [Query.or([Query.equal('status', ['active', 'paused']), Query.isNull('status')])]
: [];
// Fetch all matching projects so we can filter inaccessible ones before paginating.
// Most orgs have well under 100 projects; this avoids broken pagination from client-side
// filtering of server-paginated results.
const allProjectsResult = await sdk.forConsole.organization(params.organization).listProjects({
const activeProjects = await sdk.forConsole.organization(params.organization).listProjects({
queries: [
...searchQueries,
...activeQueries,
Query.limit(100),
Query.offset(offset),
Query.limit(limit),
Query.orderDesc(''),
Query.equal('teamId', params.organization)
]
});
const enrichedResults = await Promise.all(
allProjectsResult.projects.map(async (project) => {
const projects = await Promise.all(
activeProjects.projects.map(async (project) => {
project.region ??= 'default';
const platformList = await sdk
.forProject(project.region, project.$id)
.project.listPlatforms({ queries: [Query.limit(3)] })
.catch(() => null);
if (!platformList) return null;
.catch(() => ({ platforms: [], total: 0 }));
return {
...project,
@@ -63,18 +59,13 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
})
);
const accessibleProjects = enrichedResults.filter((p) => p !== null);
const total = accessibleProjects.length;
const paginatedProjects = accessibleProjects.slice(offset, offset + limit);
return {
limit,
offset,
search,
projects: {
...allProjectsResult,
projects: paginatedProjects,
total
...activeProjects,
projects
}
};
};