"use strict";
/*
 * ATTENTION: An "eval-source-map" devtool has been used.
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
self["webpackHotUpdate_N_E"]("middleware",{

/***/ "(middleware)/./src/lib/admin-session.ts":
/*!**********************************!*\
  !*** ./src/lib/admin-session.ts ***!
  \**********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   COOKIE_NAME_ADMIN: () => (/* binding */ COOKIE_NAME_ADMIN),\n/* harmony export */   cookieOptions: () => (/* binding */ cookieOptions),\n/* harmony export */   createAdminSession: () => (/* binding */ createAdminSession),\n/* harmony export */   getAdminSession: () => (/* binding */ getAdminSession),\n/* harmony export */   verifyAdminSession: () => (/* binding */ verifyAdminSession)\n/* harmony export */ });\n/* harmony import */ var next_headers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! next/headers */ \"(middleware)/./node_modules/next/dist/esm/api/headers.js\");\n\nconst COOKIE_NAME = \"admin_session\";\nconst SEP = \".\";\nfunction getSecret() {\n    const secret = process.env.ADMIN_SESSION_SECRET;\n    if (!secret) throw new Error(\"ADMIN_SESSION_SECRET env var is not set\");\n    return secret;\n}\nasync function sign(payload) {\n    const encoder = new TextEncoder();\n    const key = await crypto.subtle.importKey(\"raw\", encoder.encode(getSecret()), {\n        name: \"HMAC\",\n        hash: \"SHA-256\"\n    }, false, [\n        \"sign\"\n    ]);\n    const sig = await crypto.subtle.sign(\"HMAC\", key, encoder.encode(payload));\n    return btoa(String.fromCharCode(...new Uint8Array(sig)));\n}\nasync function createAdminSession(data) {\n    const payload = btoa(JSON.stringify(data));\n    return payload + SEP + await sign(payload);\n}\nasync function verifyAdminSession(token) {\n    const sepIdx = token.lastIndexOf(SEP);\n    if (sepIdx === -1) return null;\n    const payload = token.slice(0, sepIdx);\n    const sig = token.slice(sepIdx + 1);\n    const expectedSig = await sign(payload);\n    if (sig.length !== expectedSig.length) return null;\n    try {\n        if (!constantTimeEqual(sig, expectedSig)) return null;\n    } catch  {\n        return null;\n    }\n    try {\n        return JSON.parse(atob(payload));\n    } catch  {\n        return null;\n    }\n}\nfunction constantTimeEqual(a, b) {\n    if (a.length !== b.length) return false;\n    let result = 0;\n    for(let i = 0; i < a.length; i++){\n        result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n    }\n    return result === 0;\n}\nconst COOKIE_NAME_ADMIN = COOKIE_NAME;\nfunction cookieOptions(value) {\n    return {\n        name: COOKIE_NAME,\n        value,\n        httpOnly: true,\n        secure: \"development\" === \"production\",\n        sameSite: \"lax\",\n        path: \"/admin\"\n    };\n}\nasync function getAdminSession() {\n    const store = await (0,next_headers__WEBPACK_IMPORTED_MODULE_0__.cookies)();\n    const token = store.get(COOKIE_NAME)?.value;\n    if (!token) return null;\n    return verifyAdminSession(token);\n}\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 6060 characters]\n//# sourceURL=webpack-internal:///(middleware)/./src/lib/admin-session.ts\n");

/***/ })

});