import type { SessionData } from "./useSession.ts"; /** * Check if the current user is an admin based on VITE_ADMIN_DIDS environment variable. * VITE_ADMIN_DIDS should be a comma-separated list of DIDs. */ export function isAdmin(session: SessionData | null): boolean { if (!session?.authenticated || !session.user?.did) { return false; } const adminDids = import.meta.env.VITE_ADMIN_DIDS; if (!adminDids) { return false; } const adminList = adminDids .split(",") .map((did: string) => did.trim()) .filter(Boolean); return adminList.includes(session.user.did); } /** * Check if the current user is the owner of a slice or an admin. * * @param slice - The slice object with did and actorHandle fields * @param session - The current user session * @returns true if the user is the owner or an admin, false otherwise */ export function isSliceOwner( slice: { did?: string | null; actorHandle?: string | null } | null | undefined, session: SessionData | null, ): boolean { if (!session?.authenticated || !session.user) { return false; } // Check if user is an admin if (isAdmin(session)) { return true; } // Check if user is the slice owner if (!slice) { return false; } return ( slice.did === session.user.did || slice.actorHandle === session.user.handle ); }