66 * Copyright Oxide Computer Company
77 */
88
9- import { useQuery } from '@tanstack/react-query'
10-
11- import { apiqErrorsAllowed , usePrefetchedApiQuery } from '~/api/client'
12- import { invariant } from '~/util/invariant'
9+ import { apiq , usePrefetchedQuery } from '~/api/client'
1310
1411/**
1512 * Access all the data fetched by the loader. Because of the `shouldRevalidate`
@@ -18,19 +15,7 @@ import { invariant } from '~/util/invariant'
1815 * loaders.
1916 */
2017export function useCurrentUser ( ) {
21- const { data : me } = usePrefetchedApiQuery ( 'currentUserView' , { } )
22- const { data : myGroups } = usePrefetchedApiQuery ( 'currentUserGroups' , { } )
23-
24- // User can only get to system routes if they have viewer perms (at least) on
25- // the fleet. The natural place to find out whether they have such perms is
26- // the fleet (system) policy, but if the user doesn't have fleet read, we'll
27- // get a 403 from that endpoint. So we simply check whether that endpoint 200s
28- // or not to determine whether the user is a fleet viewer.
29- const { data : systemPolicy } = useQuery ( apiqErrorsAllowed ( 'systemPolicyView' , { } ) )
30- // don't use usePrefetchedApiQuery because it's not worth making an errors
31- // allowed version of that
32- invariant ( systemPolicy , 'System policy must be prefetched' )
33- const isFleetViewer = systemPolicy . type === 'success'
34-
35- return { me, myGroups, isFleetViewer }
18+ const { data : me } = usePrefetchedQuery ( apiq ( 'currentUserView' , { } ) )
19+ const { data : myGroups } = usePrefetchedQuery ( apiq ( 'currentUserGroups' , { } ) )
20+ return { me, myGroups }
3621}
0 commit comments