"use strict";(()=>{var e={};e.id=8873,e.ids=[8873],e.modules={20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},84770:e=>{e.exports=require("crypto")},96345:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>g,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{POST:()=>c});var o=r(49303),a=r(88716),l=r(60670),i=r(87070),u=r(23402);let s=(0,u.H2)();async function c(e){try{let t="global",r=s.checkLimit(t);if(!r.allowed)return i.NextResponse.json({error:"Too many login attempts. Please try again later."},{status:429,headers:{"Retry-After":String(r.retryAfter||900)}});let{token:n}=await e.json();if(!n||"string"!=typeof n||n.length>256)return s.recordFailure(t),i.NextResponse.json({error:"Token is required"},{status:400});if(!(0,u.WX)(n))return s.recordFailure(t),i.NextResponse.json({error:"Invalid token"},{status:401});s.recordSuccess(t);let o=(0,u.n8)(),a=o>0?o:u.pC,l=i.NextResponse.json({success:!0});return l.cookies.set(u.HI,n,(0,u.Gn)(a)),l}catch{return i.NextResponse.json({error:"Internal server error"},{status:500})}}let p=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/auth/login/route",pathname:"/api/auth/login",filename:"route",bundlePath:"app/api/auth/login/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/auth/login/route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:d,staticGenerationAsyncStorage:m,serverHooks:f}=p,h="/api/auth/login/route";function g(){return(0,l.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},23402:(e,t,r)=>{r.d(t,{HI:()=>a,pC:()=>u,Gn:()=>f,H2:()=>h,n8:()=>m,KL:()=>d,WX:()=>p});var n=r(84770),o=r.n(n);let a="cm_auth_token",l=/^[0-9a-f]{64}$/,i={maxAttempts:5,lockoutDuration:9e5,cleanupInterval:36e5},u=86400,s=(()=>{let e=process.env.CM_AUTH_TOKEN_HASH||void 0;if(e){if(!function(e){return!!e&&l.test(e)}(e)){console.error("[auth] CM_AUTH_TOKEN_HASH is not a valid SHA-256 hash");return}return e}})(),c=function(){let e=process.env.CM_AUTH_EXPIRE,t=Date.now();if(e)try{return t+function(e){let t=e.match(/^(\d+)([hdm])$/);if(!t)throw Error(`Invalid duration format: "${e}". Use Nh, Nd, or Nm (e.g., "24h", "7d", "90m")`);let r=parseInt(t[1],10),n=t[2],o={h:36e5,d:864e5,m:6e4}[n];if(void 0===o)throw Error(`Invalid duration unit: "${n}"`);let a=r*o;if(a<36e5)throw Error(`Duration too short: minimum is 1h (60m). Got: "${e}"`);if(a>2592e6)throw Error(`Duration too long: maximum is 30d (720h). Got: "${e}"`);return a}(e)}catch{return t+864e5}return process.env.CM_AUTH_TOKEN_HASH?t+864e5:null}();function p(e){if(!s||!e||"string"!=typeof e||null!==c&&Date.now()>c)return!1;let t=o().createHash("sha256").update(e).digest("hex"),r=Buffer.from(t,"hex"),n=Buffer.from(s,"hex");return r.length===n.length&&o().timingSafeEqual(r,n)}function d(){return!!s}function m(){if(null===c)return 0;let e=c-Date.now();return e<=0?0:Math.floor(e/1e3)}function f(e){return{httpOnly:!0,sameSite:"strict",secure:!!process.env.CM_HTTPS_CERT,maxAge:e,path:"/"}}function h(){let e=new Map,t=setInterval(()=>{let t=Date.now();for(let[r,n]of e){let o=null===n.lockedUntil||t>n.lockedUntil,a=t-n.lastAttempt>i.lockoutDuration;o&&a&&e.delete(r)}},i.cleanupInterval);return t.unref&&t.unref(),{checkLimit(t){let r=e.get(t);if(!r)return{allowed:!0};if(null!==r.lockedUntil){let e=Date.now();if(e<r.lockedUntil)return{allowed:!1,retryAfter:Math.ceil((r.lockedUntil-e)/1e3)};r.attempts=0,r.lockedUntil=null}return{allowed:!0}},recordFailure(t){let r=Date.now(),n=e.get(t)||{attempts:0,lockedUntil:null,lastAttempt:r};n.attempts++,n.lastAttempt=r,n.attempts>=i.maxAttempts&&(n.lockedUntil=r+i.lockoutDuration),e.set(t,n)},recordSuccess(t){e.delete(t)},destroy(){clearInterval(t),e.clear()}}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8948,5972],()=>r(96345));module.exports=n})();