import { z as executeAsync, D as hash } from '../nitro/nitro.mjs'; import { d as defineNuxtRouteMiddleware, n as navigateTo, f as fetchDefaults, a as useNuxtApp, b as asyncDataDefaults, c as createError } from './server.mjs'; import { computed, toValue, reactive, watch, getCurrentInstance, onServerPrefetch, ref, shallowRef, toRef, nextTick, unref, defineComponent, createElementBlock, provide, cloneVNode, h } from 'vue'; import { isPlainObject } from '@vue/shared'; import { debounce } from 'perfect-debounce'; import 'node:http'; import 'node:https'; import 'node:events'; import 'node:buffer'; import 'node:fs'; import 'node:path'; import 'node:crypto'; import 'node:url'; import '../routes/renderer.mjs'; import 'vue-bundle-renderer/runtime'; import 'vue/server-renderer'; import 'unhead/server'; import 'devalue'; import 'unhead/utils'; import 'unhead/plugins'; import 'vue-router'; import 'lucide-vue-next'; function useRequestEvent(nuxtApp) { var _a; nuxtApp || (nuxtApp = useNuxtApp()); return (_a = nuxtApp.ssrContext) == null ? void 0 : _a.event; } function useRequestFetch() { var _a; return ((_a = useRequestEvent()) == null ? void 0 : _a.$fetch) || globalThis.$fetch; } defineComponent({ name: "ServerPlaceholder", render() { return createElementBlock("div"); } }); const clientOnlySymbol = Symbol.for("nuxt:client-only"); defineComponent({ name: "ClientOnly", inheritAttrs: false, props: ["fallback", "placeholder", "placeholderTag", "fallbackTag"], ...false, setup(props, { slots, attrs }) { const mounted = shallowRef(false); const vm = getCurrentInstance(); if (vm) { vm._nuxtClientOnly = true; } provide(clientOnlySymbol, true); return () => { var _a; if (mounted.value) { const vnodes = (_a = slots.default) == null ? void 0 : _a.call(slots); if (vnodes && vnodes.length === 1) { return [cloneVNode(vnodes[0], attrs)]; } return vnodes; } const slot = slots.fallback || slots.placeholder; if (slot) { return h(slot); } const fallbackStr = props.fallback || props.placeholder || ""; const fallbackTag = props.fallbackTag || props.placeholderTag || "span"; return createElementBlock(fallbackTag, attrs, fallbackStr); }; } }); const isDefer = (dedupe) => dedupe === "defer" || dedupe === false; function useAsyncData(...args) { var _a, _b, _c, _d, _e, _f, _g; const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0; if (_isAutoKeyNeeded(args[0], args[1])) { args.unshift(autoKey); } let [_key, _handler, options = {}] = args; const key = computed(() => toValue(_key)); if (typeof key.value !== "string") { throw new TypeError("[nuxt] [useAsyncData] key must be a string."); } if (typeof _handler !== "function") { throw new TypeError("[nuxt] [useAsyncData] handler must be a function."); } const nuxtApp = useNuxtApp(); (_a = options.server) != null ? _a : options.server = true; (_b = options.default) != null ? _b : options.default = getDefault; (_c = options.getCachedData) != null ? _c : options.getCachedData = getDefaultCachedData; (_d = options.lazy) != null ? _d : options.lazy = false; (_e = options.immediate) != null ? _e : options.immediate = true; (_f = options.deep) != null ? _f : options.deep = asyncDataDefaults.deep; (_g = options.dedupe) != null ? _g : options.dedupe = "cancel"; options._functionName || "useAsyncData"; nuxtApp._asyncData[key.value]; function createInitialFetch() { var _a2; const initialFetchOptions = { cause: "initial", dedupe: options.dedupe }; if (!((_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2._init)) { initialFetchOptions.cachedData = options.getCachedData(key.value, nuxtApp, { cause: "initial" }); nuxtApp._asyncData[key.value] = createAsyncData(nuxtApp, key.value, _handler, options, initialFetchOptions.cachedData); } return () => nuxtApp._asyncData[key.value].execute(initialFetchOptions); } const initialFetch = createInitialFetch(); const asyncData = nuxtApp._asyncData[key.value]; asyncData._deps++; const fetchOnServer = options.server !== false && nuxtApp.payload.serverRendered; if (fetchOnServer && options.immediate) { const promise = initialFetch(); if (getCurrentInstance()) { onServerPrefetch(() => promise); } else { nuxtApp.hook("app:created", async () => { await promise; }); } } const asyncReturn = { data: writableComputedRef(() => { var _a2; return (_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2.data; }), pending: writableComputedRef(() => { var _a2; return (_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2.pending; }), status: writableComputedRef(() => { var _a2; return (_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2.status; }), error: writableComputedRef(() => { var _a2; return (_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2.error; }), refresh: (...args2) => { var _a2; if (!((_a2 = nuxtApp._asyncData[key.value]) == null ? void 0 : _a2._init)) { const initialFetch2 = createInitialFetch(); return initialFetch2(); } return nuxtApp._asyncData[key.value].execute(...args2); }, execute: (...args2) => asyncReturn.refresh(...args2), clear: () => clearNuxtDataByKey(nuxtApp, key.value) }; const asyncDataPromise = Promise.resolve(nuxtApp._asyncDataPromises[key.value]).then(() => asyncReturn); Object.assign(asyncDataPromise, asyncReturn); return asyncDataPromise; } function writableComputedRef(getter) { return computed({ get() { var _a; return (_a = getter()) == null ? void 0 : _a.value; }, set(value) { const ref2 = getter(); if (ref2) { ref2.value = value; } } }); } function _isAutoKeyNeeded(keyOrFetcher, fetcher) { if (typeof keyOrFetcher === "string") { return false; } if (typeof keyOrFetcher === "object" && keyOrFetcher !== null) { return false; } if (typeof keyOrFetcher === "function" && typeof fetcher === "function") { return false; } return true; } function clearNuxtDataByKey(nuxtApp, key) { if (key in nuxtApp.payload.data) { nuxtApp.payload.data[key] = void 0; } if (key in nuxtApp.payload._errors) { nuxtApp.payload._errors[key] = asyncDataDefaults.errorValue; } if (nuxtApp._asyncData[key]) { nuxtApp._asyncData[key].data.value = void 0; nuxtApp._asyncData[key].error.value = asyncDataDefaults.errorValue; { nuxtApp._asyncData[key].pending.value = false; } nuxtApp._asyncData[key].status.value = "idle"; } if (key in nuxtApp._asyncDataPromises) { if (nuxtApp._asyncDataPromises[key]) { nuxtApp._asyncDataPromises[key].cancelled = true; } nuxtApp._asyncDataPromises[key] = void 0; } } function pick(obj, keys) { const newObj = {}; for (const key of keys) { newObj[key] = obj[key]; } return newObj; } function createAsyncData(nuxtApp, key, _handler, options, initialCachedData) { var _a, _b; (_b = (_a = nuxtApp.payload._errors)[key]) != null ? _b : _a[key] = asyncDataDefaults.errorValue; const hasCustomGetCachedData = options.getCachedData !== getDefaultCachedData; const handler = _handler ; const _ref = options.deep ? ref : shallowRef; const hasCachedData = initialCachedData != null; const unsubRefreshAsyncData = nuxtApp.hook("app:data:refresh", async (keys) => { if (!keys || keys.includes(key)) { await asyncData.execute({ cause: "refresh:hook" }); } }); const asyncData = { data: _ref(hasCachedData ? initialCachedData : options.default()), pending: shallowRef(!hasCachedData), error: toRef(nuxtApp.payload._errors, key), status: shallowRef("idle"), execute: (...args) => { var _a2, _b2; const [_opts, newValue = void 0] = args; const opts = _opts && newValue === void 0 && typeof _opts === "object" ? _opts : {}; if (nuxtApp._asyncDataPromises[key]) { if (isDefer((_a2 = opts.dedupe) != null ? _a2 : options.dedupe)) { return nuxtApp._asyncDataPromises[key]; } nuxtApp._asyncDataPromises[key].cancelled = true; } if (opts.cause === "initial" || nuxtApp.isHydrating) { const cachedData = "cachedData" in opts ? opts.cachedData : options.getCachedData(key, nuxtApp, { cause: (_b2 = opts.cause) != null ? _b2 : "refresh:manual" }); if (cachedData != null) { nuxtApp.payload.data[key] = asyncData.data.value = cachedData; asyncData.error.value = asyncDataDefaults.errorValue; asyncData.status.value = "success"; return Promise.resolve(cachedData); } } { asyncData.pending.value = true; } asyncData.status.value = "pending"; const promise = new Promise( (resolve, reject) => { try { resolve(handler(nuxtApp)); } catch (err) { reject(err); } } ).then(async (_result) => { if (promise.cancelled) { return nuxtApp._asyncDataPromises[key]; } let result = _result; if (options.transform) { result = await options.transform(_result); } if (options.pick) { result = pick(result, options.pick); } nuxtApp.payload.data[key] = result; asyncData.data.value = result; asyncData.error.value = asyncDataDefaults.errorValue; asyncData.status.value = "success"; }).catch((error) => { if (promise.cancelled) { return nuxtApp._asyncDataPromises[key]; } asyncData.error.value = createError(error); asyncData.data.value = unref(options.default()); asyncData.status.value = "error"; }).finally(() => { if (promise.cancelled) { return; } { asyncData.pending.value = false; } delete nuxtApp._asyncDataPromises[key]; }); nuxtApp._asyncDataPromises[key] = promise; return nuxtApp._asyncDataPromises[key]; }, _execute: debounce((...args) => asyncData.execute(...args), 0, { leading: true }), _default: options.default, _deps: 0, _init: true, _hash: void 0, _off: () => { var _a2; unsubRefreshAsyncData(); if ((_a2 = nuxtApp._asyncData[key]) == null ? void 0 : _a2._init) { nuxtApp._asyncData[key]._init = false; } if (!hasCustomGetCachedData) { nextTick(() => { var _a3; if (!((_a3 = nuxtApp._asyncData[key]) == null ? void 0 : _a3._init)) { clearNuxtDataByKey(nuxtApp, key); asyncData.execute = () => Promise.resolve(); asyncData.data.value = asyncDataDefaults.value; } }); } } }; return asyncData; } const getDefault = () => asyncDataDefaults.value; const getDefaultCachedData = (key, nuxtApp, ctx) => { if (nuxtApp.isHydrating) { return nuxtApp.payload.data[key]; } if (ctx.cause !== "refresh:manual" && ctx.cause !== "refresh:hook") { return nuxtApp.static.data[key]; } }; function useFetch(request, arg1, arg2) { const [opts = {}, autoKey] = [{}, arg1]; const _request = computed(() => toValue(request)); const key = computed(() => toValue(opts.key) || "$f" + hash([autoKey, typeof _request.value === "string" ? _request.value : "", ...generateOptionSegments(opts)])); if (!opts.baseURL && typeof _request.value === "string" && (_request.value[0] === "/" && _request.value[1] === "/")) { throw new Error('[nuxt] [useFetch] the request URL must not start with "//".'); } const { server, lazy, default: defaultFn, transform, pick: pick2, watch: watchSources, immediate, getCachedData, deep, dedupe, ...fetchOptions } = opts; const _fetchOptions = reactive({ ...fetchDefaults, ...fetchOptions, cache: typeof opts.cache === "boolean" ? void 0 : opts.cache }); const _asyncDataOptions = { server, lazy, default: defaultFn, transform, pick: pick2, immediate, getCachedData, deep, dedupe, watch: watchSources === false ? [] : [...watchSources || [], _fetchOptions] }; if (!immediate) { let setImmediate = function() { _asyncDataOptions.immediate = true; }; watch(key, setImmediate, { flush: "sync", once: true }); watch([...watchSources || [], _fetchOptions], setImmediate, { flush: "sync", once: true }); } let controller; const asyncData = useAsyncData(watchSources === false ? key.value : key, () => { var _a; (_a = controller == null ? void 0 : controller.abort) == null ? void 0 : _a.call(controller, new DOMException("Request aborted as another request to the same endpoint was initiated.", "AbortError")); controller = typeof AbortController !== "undefined" ? new AbortController() : {}; const timeoutLength = toValue(opts.timeout); let timeoutId; if (timeoutLength) { timeoutId = setTimeout(() => controller.abort(new DOMException("Request aborted due to timeout.", "AbortError")), timeoutLength); controller.signal.onabort = () => clearTimeout(timeoutId); } let _$fetch = opts.$fetch || globalThis.$fetch; if (!opts.$fetch) { const isLocalFetch = typeof _request.value === "string" && _request.value[0] === "/" && (!toValue(opts.baseURL) || toValue(opts.baseURL)[0] === "/"); if (isLocalFetch) { _$fetch = useRequestFetch(); } } return _$fetch(_request.value, { signal: controller.signal, ..._fetchOptions }).finally(() => { clearTimeout(timeoutId); }); }, _asyncDataOptions); return asyncData; } function generateOptionSegments(opts) { var _a; const segments = [ ((_a = toValue(opts.method)) == null ? void 0 : _a.toUpperCase()) || "GET", toValue(opts.baseURL) ]; for (const _obj of [opts.params || opts.query]) { const obj = toValue(_obj); if (!obj) { continue; } const unwrapped = {}; for (const [key, value] of Object.entries(obj)) { unwrapped[toValue(key)] = toValue(value); } segments.push(unwrapped); } if (opts.body) { const value = toValue(opts.body); if (!value) { segments.push(hash(value)); } else if (value instanceof ArrayBuffer) { segments.push(hash(Object.fromEntries([...new Uint8Array(value).entries()].map(([k, v]) => [k, v.toString()])))); } else if (value instanceof FormData) { const obj = {}; for (const entry of value.entries()) { const [key, val] = entry; obj[key] = val instanceof File ? val.name : val; } segments.push(hash(obj)); } else if (isPlainObject(value)) { segments.push(hash(reactive(value))); } else { try { segments.push(hash(value)); } catch { console.warn("[useFetch] Failed to hash body", value); } } } return segments; } const auth = defineNuxtRouteMiddleware(async (to, from) => { let __temp, __restore; const protectedRoutes = ["/mitgliederbereich", "/cms"]; const requiresAuth = protectedRoutes.some((route) => to.path.startsWith(route)); if (!requiresAuth) { return; } try { const { data: auth2 } = ([__temp, __restore] = executeAsync(() => useFetch("/api/auth/status", "$iafshigZRx")), __temp = await __temp, __restore(), __temp); if (!auth2.value || !auth2.value.isLoggedIn) { return navigateTo("/login?redirect=" + to.path); } if (to.path.startsWith("/cms")) { const isAdmin = auth2.value.role === "admin" || auth2.value.role === "vorstand"; if (!isAdmin) { return navigateTo("/mitgliederbereich"); } } } catch (error) { return navigateTo("/login?redirect=" + to.path); } }); export { auth as default }; //# sourceMappingURL=auth-D7NaNMED.mjs.map