diff --git a/composables/user.ts b/composables/user.ts index 23e4b1b..b99996f 100644 --- a/composables/user.ts +++ b/composables/user.ts @@ -2,18 +2,26 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query' import type { User } from '~/shared/types' const queryKeyFactory = { - user: ['user'], + currentUser: ['current-user'], + users: ['users'], } export function useUser() { const firebaseCurrentUser = useCurrentUser() return useQuery({ - queryKey: queryKeyFactory.user, + queryKey: queryKeyFactory.currentUser, queryFn: () => $api(`/api/user/${firebaseCurrentUser.value?.uid}`), enabled: computed(() => !!firebaseCurrentUser.value), // Only run when user exists }) } +export function useUsers() { + return useQuery({ + queryKey: queryKeyFactory.users, + queryFn: () => $api(`/api/user`), + }) +} + export function useUserSignOutMutation() { const auth = useFirebaseAuth() const queryClient = useQueryClient() diff --git a/pages/admin/members/index.vue b/pages/admin/members/index.vue index aab0be7..5f6ecab 100644 --- a/pages/admin/members/index.vue +++ b/pages/admin/members/index.vue @@ -1,5 +1,13 @@ + + diff --git a/server/api/user/index.get.ts b/server/api/user/index.get.ts index 6a3a2b1..2d48b8c 100644 --- a/server/api/user/index.get.ts +++ b/server/api/user/index.get.ts @@ -1,5 +1,14 @@ export default defineProtectedEventHandler((event) => { - return event.context.database.query.users.findMany() + return event.context.database.query.users.findMany({ + columns: { + id: true, + memberId: true, + memberType: true, + name: true, + email: true, + graduationYear: true, + }, + }) }, { cache: { maxAge: 60,