All files / web/src/hooks use-auth-status.ts

100% Statements 13/13
100% Branches 2/2
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28    1x 1x   1x 1x 1x 1x                     1x 14x 14x 14x 14x   14x 14x  
'use client';
 
import { useQuery } from '@tanstack/react-query';
import { type AuthStatus, getAuthStatus } from '@web/api/v1/super-agents/auth';
 
export const authStatusQueryKeys = {
  all: ['auth-status'] as const,
  detail: () => [...authStatusQueryKeys.all, 'detail'] as const,
};
 
/**
 * The dashboard's authentication status, or null while it loads and whenever
 * the server could not be reached.
 *
 * `authRequired` is false when the server has no ACCESS_PASSWORD set. Nothing
 * that offers to end a session should render in that case: there is no session
 * to end, and `/login` sends an arriving visitor straight back to the
 * dashboard.
 */
export function useAuthStatus(): AuthStatus | null {
  const { data = null } = useQuery({
    queryKey: authStatusQueryKeys.detail(),
    queryFn: getAuthStatus,
  });
 
  return data;
}