import type { Core } from "@strapi/strapi";

export default (_config: unknown, _ctx: { strapi: Core.Strapi }) => {
  return async (ctx: any, next: () => Promise<void>) => {
    const path = ctx?.path || "";
    const method = (ctx?.method || "").toUpperCase();

    const isRegisterPath =
      path === "/api/auth/local/register" || path === "/auth/local/register";

    if (isRegisterPath && method === "POST") {
      // Return 404 so the register endpoint is effectively inaccessible.
      ctx.status = 404;
      ctx.body = { error: "Not Found" };
      return;
    }

    await next();
  };
};
