'use server' import { getServerSession } from "next-auth"; import { authOptions } from "@/app/auth"; import type { ApiResponse } from "@/lib/backend-types"; import type { UserProfile } from "@/lib/types/user"; import { handleApiResponse } from "@/utils/tryCatch"; type ParamProps = { [key: string]: string | number | undefined; }; export async function getUsers(params: ParamProps) { const session = await getServerSession(authOptions); const query = Object.entries(params) .filter(([_, value]) => value !== undefined && value !== "") .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`) .join("&"); const response = await fetch( `${process.env.SARLINK_API_BASE_URL}/api/auth/users/?${query}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Token ${session?.apiToken}`, }, }, ); return handleApiResponse>(response, "getUsers"); }