"use client";

import { useLoginModal } from "@/app/LoginModalContext";
import { useAuthContext } from "@/app/AuthContext";

export class AuthRequiredError extends Error {
  constructor() {
    super("Authentication required");
    this.name = "AuthRequiredError";
  }
}

export function useAuthAction() {
  const { openLoginModal } = useLoginModal();
  const { did } = useAuthContext();

  return () => {
    if (!did) {
      openLoginModal();
      throw new AuthRequiredError();
    }
  };
}
