1
2
3
4
5
6
7
8
9
10
11
12
13
14
15import { useQuery } from '@tanstack/react-query';
import { useGlobalStore } from '../utils';
import * as API from 'aws-amplify/api';
const apiClient = API.generateClient();
export const useUser = () => {
const { authenticated } = useGlobalStore();
return useQuery({
queryKey: ['user', authenticated],
queryFn: async () => (await apiClient.graphql({
query: `query($id: uuid!) {users_by_pk(id: $id) {id name}}`,
variables: { id: authenticated },
}))?.data?.users_by_pk,
});
}