import { r as redirect, e as error } from './index-wpIsICWW.js';
import { type } from 'arktype';
import { f as formDataToObject } from './utils2-BNPuf_o4.js';

function requireUserMiddleware(event) {
  if (!event.locals.user) {
    const queryString = new URLSearchParams({
      goto: event.url.pathname
    }).toString();
    redirect(307, `/sign-in?${queryString}`);
  }
  return (
    /** @type {User} */
    event.locals.user
  );
}
async function validateBodyMiddleware(schema, event) {
  const formData = await event.request.formData();
  const body = formDataToObject(formData);
  const validated = schema(body);
  if (validated instanceof type.errors) {
    error(400, validated.summary);
  }
  return (
    /** @type {Exclude<ReturnType<T>, import('arktype').ArkErrors>} */
    validated
  );
}

export { requireUserMiddleware as r, validateBodyMiddleware as v };
//# sourceMappingURL=middleware-DEO9L-XC.js.map
