import { z } from "zod";

const hexSchema = z
  .string()
  .regex(/^[0-9a-fA-F]{24}$/, "Invalid organization ID");

export default defineNuxtRouteMiddleware(async (to, from) => {
  if (import.meta.server) return;

  const { organization, org } = to.params;

  // console.log('org-aut-middleware running', hexSchema.safeParse(organization).success)
  
  if (!hexSchema.safeParse(organization || org).success) {
    console.log('[02.org] middleware run')
    return navigateTo(
      { name: "require-organization-membership" },
      { replace: true }
    );
  }
});
