export default defineNuxtRouteMiddleware(async (route) => {
  const { cookieConfig } = useRuntimeConfig().public;

  // Get access token from cookies
  const sid = useCookie("sid", cookieConfig).value;

  const serviceProviderEmail = (route.query.email as string) ?? "";

  console.log(serviceProviderEmail);

  if (serviceProviderEmail) {
    useCookie("service-provider-email", cookieConfig).value =
      serviceProviderEmail;
  }

  if (!sid) {
    // Redirect to login page if no access token
    return navigateTo({ name: "index" });
  }
});
