Scope /mycards and dashboard to own cards only

The Directus read permission intentionally allows friends' collections
(used by /friends/[username]); the own-collection pages need an explicit
user = current-user filter on top of it.
This commit is contained in:
2026-07-28 23:55:31 +02:00
parent fd2d5408d6
commit 1cfbf1db49
2 changed files with 13 additions and 4 deletions
+6 -2
View File
@@ -14,9 +14,13 @@ if (!isLoggedIn(Astro.locals)) {
return Astro.redirect("/login"); return Astro.redirect("/login");
} }
// Owner-scoping is enforced by the Directus permissions // Own cards only (the read permission also allows friends' collections,
// which is what /friends/[username] uses — here we want just ours)
const myCards = (await directus!.request( const myCards = (await directus!.request(
readItems("mycards", { limit: -1 }), readItems("mycards", {
filter: { user: { _eq: Astro.locals.user!.id } },
limit: -1,
}),
)) as MyCardRecord[]; )) as MyCardRecord[];
// Fetch prices through the 24h-cached card endpoint // Fetch prices through the 24h-cached card endpoint
+7 -2
View File
@@ -13,9 +13,14 @@ if (!isLoggedIn(Astro.locals)) {
return Astro.redirect("/login"); return Astro.redirect("/login");
} }
// Fetch all user's cards (owner-scoping enforced by Directus permissions) // Own cards only (the read permission also allows friends' collections,
// which is what /friends/[username] uses — here we want just ours)
const myCards = (await directus!.request( const myCards = (await directus!.request(
readItems("mycards", { sort: ["-date_created"], limit: -1 }), readItems("mycards", {
filter: { user: { _eq: Astro.locals.user!.id } },
sort: ["-date_created"],
limit: -1,
}),
)) as MyCardRecord[]; )) as MyCardRecord[];
const cardsWithPrice = await priceCollectionCards(myCards); const cardsWithPrice = await priceCollectionCards(myCards);