refactor(users): some user refactoring and configuring
This commit is contained in:
40
frontend/src/lib/queries/getUsers.ts
Normal file
40
frontend/src/lib/queries/getUsers.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { keepPreviousData, queryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { authClient } from "../auth-client";
|
||||
|
||||
export function getUsers() {
|
||||
return queryOptions({
|
||||
queryKey: ["getUsers"],
|
||||
queryFn: () => fetch(),
|
||||
staleTime: 5000,
|
||||
refetchOnWindowFocus: true,
|
||||
placeholderData: keepPreviousData,
|
||||
});
|
||||
}
|
||||
|
||||
const fetch = async () => {
|
||||
if (window.location.hostname === "localhost") {
|
||||
await new Promise((res) => setTimeout(res, 1500));
|
||||
}
|
||||
|
||||
const { data, error } = await authClient.admin.listUsers({
|
||||
query: {
|
||||
// searchValue: "some name",
|
||||
// searchField: "name",
|
||||
// searchOperator: "contains",
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
sortBy: "name",
|
||||
// sortDirection: "desc",
|
||||
// filterField: "email",
|
||||
// filterValue: "hello@example.com",
|
||||
// filterOperator: "eq",
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return data.users;
|
||||
};
|
||||
Reference in New Issue
Block a user