import { useContext } from "react";
import { AuthContext, type AuthContextValue } from "../providers/AuthProvider";

/**
 * Access authentication state and actions from a mounted AuthProvider.
 *
 * @throws {Error} When called outside of `<AuthProvider>`.
 */
export function useAuth(): AuthContextValue {
  const ctx = useContext(AuthContext);
  if (ctx === null) {
    throw new Error("useAuth must be used within <AuthProvider>.");
  }
  return ctx;
}
