MCPcopy Create free account
hub / github.com/dailydotdev/apps / useCheckCoresRole

Function useCheckCoresRole

packages/shared/src/hooks/useCheckCoresRole.ts:10–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { useRequestProtocol } from './useRequestProtocol';
9
10export const useCheckCoresRole = (): void => {
11 const { user, isFetched, updateUser } = useAuthContext();
12 const { requestMethod } = useRequestProtocol();
13 const { isActionsFetched, checkHasCompleted } = useActions();
14
15 useQuery({
16 queryKey: generateQueryKey(RequestKey.CheckCoresRole, user),
17 queryFn: async () => {
18 const result = await requestMethod<{
19 checkCoresRole: Pick<LoggedUser, 'coresRole'>;
20 }>(CHECK_CORES_ROLE_QUERY);
21
22 if (result.checkCoresRole.coresRole !== user!.coresRole) {
23 await updateUser({
24 ...user!,
25 coresRole: result.checkCoresRole.coresRole,
26 });
27 }
28
29 return result.checkCoresRole;
30 },
31 staleTime: Infinity,
32 gcTime: Infinity,
33 enabled:
34 !!user &&
35 isFetched &&
36 isActionsFetched &&
37 !checkHasCompleted(ActionType.CheckedCoresRole),
38 });
39};

Callers 2

InternalAppFunction · 0.90
InternalAppFunction · 0.90

Calls 4

useAuthContextFunction · 0.90
useRequestProtocolFunction · 0.90
useActionsFunction · 0.90
generateQueryKeyFunction · 0.90

Tested by

no test coverage detected