mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-15 11:05:50 +00:00
feat: implement user verification and rejection functionality with improved error handling ✨
This commit is contained in:
31
queries/users.ts
Normal file
31
queries/users.ts
Normal file
@ -0,0 +1,31 @@
|
||||
'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<ApiResponse<UserProfile>>(response, "getUsers");
|
||||
}
|
Reference in New Issue
Block a user