Refactor code

This commit is contained in:
2026-02-03 12:17:47 +01:00
parent ea5eb6fa59
commit 8572e22c5d
185 changed files with 1268 additions and 1458 deletions

View File

@ -3,20 +3,13 @@
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { headers } from "next/headers";
import type { SessionWithRole } from "@/types/auth";
import type { UsersListRow } from "@/types/users";
export type UsersListRow = {
id: string;
name: string | null;
email: string;
role: "admin" | "user";
emailVerified: boolean;
createdAt: Date;
updatedAt: Date;
};
// Returns all users for the admin users table.
export async function getUsers(): Promise<UsersListRow[]> {
const session = await auth.api.getSession({ headers: await headers() });
const role = (session as any)?.user?.role as string | undefined;
const role = (session as SessionWithRole)?.user?.role;
if (!session || role !== "admin") {
throw new Error("Forbidden");
@ -35,5 +28,9 @@ export async function getUsers(): Promise<UsersListRow[]> {
},
});
return rows as UsersListRow[];
return rows.map((r) => ({
...r,
createdAt: r.createdAt.toISOString(),
updatedAt: r.updatedAt.toISOString(),
}));
}