yoyojoe
yoyojoe
BABetter Auth
Created by yoyojoe on 3/13/2025 in #help
Admin Users Count
Hi. I am currently trying to get just the count of admin users. My query looks like the following:
// Admin count query - separate optimized query just for counting
const { data: adminData } = useQuery<UsersResponse>({
queryKey: ["users-admin-count"],
queryFn: async () => {
try {
const data = await client.admin.listUsers(
{
query: {
limit: 1, // We only need the total count, not the actual users
filterField: "role",
filterOperator: "eq",
filterValue: "admin"
}
},
{
throw: true,
},
);
return data as UsersResponse;
} catch (error: any) {
console.error("Failed to fetch admin count:", error);
return { users: [], total: 0 } as UsersResponse;
}
},
// Keep the count cached for longer since it doesn't change as frequently
staleTime: 5 * 60 * 1000, // 5 minutes
});
// Admin count query - separate optimized query just for counting
const { data: adminData } = useQuery<UsersResponse>({
queryKey: ["users-admin-count"],
queryFn: async () => {
try {
const data = await client.admin.listUsers(
{
query: {
limit: 1, // We only need the total count, not the actual users
filterField: "role",
filterOperator: "eq",
filterValue: "admin"
}
},
{
throw: true,
},
);
return data as UsersResponse;
} catch (error: any) {
console.error("Failed to fetch admin count:", error);
return { users: [], total: 0 } as UsersResponse;
}
},
// Keep the count cached for longer since it doesn't change as frequently
staleTime: 5 * 60 * 1000, // 5 minutes
});
but the response looks like the following although the docs state that the "total" in the meta data is the count after the filters:
{
"users": [
{
"id": "****",
"name": "***",
"email": "***",
"emailVerified": ***,
"image": "***",
"createdAt": "****",
"updatedAt": "****",
"role": "admin",
"banned": null,
"banReason": null,
"banExpires": null
}
],
"total": 6,
"limit": 1
}
{
"users": [
{
"id": "****",
"name": "***",
"email": "***",
"emailVerified": ***,
"image": "***",
"createdAt": "****",
"updatedAt": "****",
"role": "admin",
"banned": null,
"banReason": null,
"banExpires": null
}
],
"total": 6,
"limit": 1
}
Any insight into this would be awesome.
7 replies
BABetter Auth
Created by yoyojoe on 2/9/2025 in #help
Correct way to create webhooks
Hi everyone. Just want to know the best practice around creating a webhook. I want to send a post request to my other server (I have a Django server I’m using for a few protected APIs) that will only happen when a new user is created. Would I use the an after hook for this? I want to send some nonsensitive user information (user name, email, user id) and store it in Django. then when a user makes a request to my other api I can verify their identity and authentication state with JWT and JWKs.
4 replies