All files / app/features/userQueries useCurrentUser.ts

76.92% Statements 10/13
25% Branches 1/4
100% Functions 1/1
83.33% Lines 10/12

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 168x 8x 8x 8x   8x 671x 671x 671x 671x       671x    
import { useAuthContext } from "features/auth/AuthProvider";
import { useUser } from "features/userQueries/useUsers";
import { useRouter } from "next/router";
import { loginRoute } from "routes";
 
export default function useCurrentUser() {
  const authState = useAuthContext().authState;
  const userQuery = useUser(authState.userId ?? undefined);
  const router = useRouter();
  Iif (!authState.userId) {
    console.error("No user id available to get current user.");
    Iif (typeof window !== "undefined") router.push(loginRoute);
  }
  return userQuery;
}