20 lines
850 B
TypeScript
20 lines
850 B
TypeScript
import { createServerFn } from '@tanstack/react-start'
|
|
|
|
export const listStaffMembers = createServerFn({ method: 'GET' }).handler(async () => {
|
|
const [{ getAuth }, { getRequest }] = await Promise.all([
|
|
import('#/lib/auth-instance'),
|
|
import('@tanstack/react-start/server'),
|
|
])
|
|
|
|
const { users } = await getAuth().api.listUsers({
|
|
headers: getRequest().headers,
|
|
query: { sortBy: 'createdAt', sortDirection: 'asc', limit: 100 },
|
|
})
|
|
|
|
// `listUsers`'s return type doesn't pick up `user.additionalFields` from the
|
|
// auth config the way the actual response body does — `phone` is present at
|
|
// runtime (Better Auth includes every configured additional field on every
|
|
// user-returning endpoint) but missing from admin.d.ts's `UserWithRole` type.
|
|
return users as Array<(typeof users)[number] & { phone: string | null }>
|
|
})
|