1
0
Fork 0

feat: add Nutzerliste query (merges profiles with auth.admin.listUsers)

This commit is contained in:
Jonny 2026-07-14 22:08:04 +02:00
parent 371312fc89
commit 3013a7d52c
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import { createClient } from "@/lib/supabase/server";
import { createAdminClient } from "@/lib/supabase/admin";
import type { Role } from "@/lib/auth/roles";
export type Nutzer = {
id: string;
name: string;
email: string | null;
role: Role;
gesperrt: boolean;
};
export async function listNutzer(): Promise<Nutzer[]> {
const supabase = await createClient();
const adminClient = createAdminClient();
const [{ data: profiles }, { data: authData }] = await Promise.all([
supabase.from("profiles").select("id, name, role").order("name"),
adminClient.auth.admin.listUsers(),
]);
const authById = new Map((authData?.users ?? []).map((nutzer) => [nutzer.id, nutzer]));
return (profiles ?? []).map((profile) => {
const authUser = authById.get(profile.id);
const bannedUntil = authUser?.banned_until;
return {
id: profile.id,
name: profile.name,
email: authUser?.email ?? null,
role: profile.role as Role,
gesperrt: Boolean(bannedUntil && new Date(bannedUntil).getTime() > Date.now()),
};
});
}