diff --git a/app/play/page.tsx b/app/play/page.tsx
index b1f1fa5..c7d7749 100644
--- a/app/play/page.tsx
+++ b/app/play/page.tsx
@@ -106,7 +106,6 @@ export default function PlayPage() {
{filteredMaps.map((map) => (
-
admin.userId === userId);
+ const admin = await ctx.db
+ .query("admins")
+ .withIndex("by_userId", (q) => q.eq("userId", userId))
+ .first();
- if (isAdmin) {
+ if (admin) {
return await ctx.db
.query("maps")
.filter((q) => q.eq(q.field("isReviewed"), args.isReviewed))
@@ -250,10 +252,12 @@ export const approveMap = mutation({
throw new Error("Unauthorized");
}
- const admins = await ctx.db.query("admins").collect();
- const isAdmin = admins.some((admin) => admin.userId === userId);
+ const admin = await ctx.db
+ .query("admins")
+ .withIndex("by_userId", (q) => q.eq("userId", userId))
+ .first();
- if (!isAdmin) {
+ if (!admin) {
throw new Error("Unauthorized");
} else {
const maps = await ctx.db.query("maps").collect();
diff --git a/convex/schema.ts b/convex/schema.ts
index 97fc31b..6cabf20 100644
--- a/convex/schema.ts
+++ b/convex/schema.ts
@@ -64,5 +64,5 @@ export default defineSchema({
}).index("by_mapId_userId", ["mapId", "userId"]),
admins: defineTable({
userId: v.id("users"),
- }),
+ }).index("by_userId", ["userId"]),
});
diff --git a/convex/users.ts b/convex/users.ts
index 9d25d0d..e68413e 100644
--- a/convex/users.ts
+++ b/convex/users.ts
@@ -34,8 +34,11 @@ export const isAdmin = query({
return false;
}
- const admins = await ctx.db.query("admins").collect();
+ const admin = await ctx.db
+ .query("admins")
+ .withIndex("by_userId", (q) => q.eq("userId", userId))
+ .first();
- return admins.some((admin) => admin.userId === userId);
+ return !!admin;
},
});