(()=>{var e={};e.id=2488,e.ids=[2488],e.modules={28303:e=>{function r(e){var r=Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}r.keys=()=>[],r.resolve=r,r.id=28303,e.exports=r},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},79428:e=>{"use strict";e.exports=require("buffer")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},91645:e=>{"use strict";e.exports=require("net")},19771:e=>{"use strict";e.exports=require("process")},27910:e=>{"use strict";e.exports=require("stream")},41204:e=>{"use strict";e.exports=require("string_decoder")},66136:e=>{"use strict";e.exports=require("timers")},34631:e=>{"use strict";e.exports=require("tls")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},4573:e=>{"use strict";e.exports=require("node:buffer")},77598:e=>{"use strict";e.exports=require("node:crypto")},53053:e=>{"use strict";e.exports=require("node:diagnostics_channel")},63184:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>E,routeModule:()=>g,serverHooks:()=>U,workAsyncStorage:()=>T,workUnitAsyncStorage:()=>C});var n={};t.r(n),t.d(n,{POST:()=>A});var i=t(42706),s=t(28203),a=t(45994),o=t(34926),u=t(65658),l=t(39187),m=t(98095),c=t(50675),p=t(89249),d=t(23951),S=t(522);async function f(e){let r=String(e||"").trim();if(!r)return null;let t=(0,d.T)(),n=`
    SELECT
      id,
      name,
      permissions
    FROM ${(0,S.j)(String(process.env.AUTH_ROLES_TABLE||"roles").trim()||"roles")}
    WHERE id = ?
    LIMIT 1
  `,[i]=await t.query(n,[r]);if(!i.length)return null;let s=i[0];return{id:String(s.id||r).trim(),name:String(s.name||"").trim()||r||"Invitado",permissions:function(e){if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e);let r=String(e??"").trim();if(!r)return[];if(r.startsWith("[")&&r.endsWith("]"))try{let e=JSON.parse(r);if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e)}catch{}return r.split(",").map(e=>e.trim()).filter(e=>!!e)}(s.permissions)}}let _=u.Ik({email:u.Yj().email(),password:u.Yj().min(1)});async function A(e){try{if("mysql"!==(0,m.f)())return l.NextResponse.json({error:"Auth local deshabilitada."},{status:404});let r=await e.json().catch(()=>null),t=_.safeParse(r);if(!t.success)return l.NextResponse.json({error:"Payload invalido."},{status:400});let n=t.data.email.trim().toLowerCase(),i=t.data.password,s=await (0,c.t7)(n);if(!s||!s.passwordHash||!(0,c.zj)(s)||!await o.Ay.compare(i,s.passwordHash))return l.NextResponse.json({error:"Credenciales invalidas."},{status:401});let a=String(s.displayName||"").trim()||String(`${s.firstName||""} ${s.lastName||""}`).trim()||n,u=String(s.roleId||"").trim()||null,d=u?await f(u):null,S=Array.isArray(s.institutionIds)?s.institutionIds.map(e=>String(e||"").trim()).filter(Boolean):[],A=Array.isArray(s.permissions)?s.permissions.map(e=>String(e||"").trim()).filter(Boolean):[],g=Array.isArray(d?.permissions)?d.permissions.map(e=>String(e||"").trim()).filter(Boolean):[],T=Array.from(new Set([...g,...A])),C=(0,p.Q7)({id:String(s.id||"").trim(),email:n,roleId:u,roleName:d?.name||u,displayName:String(a||"").trim()||null,orgId:String(s.orgId||"").trim()||null,institutionIds:S,permissions:T}),U=l.NextResponse.json({success:!0,uid:String(s.id||"").trim()});return(0,p.$G)(U,C),U}catch(e){return console.error("[POST /api/auth/local-login] error:",e),l.NextResponse.json({error:"Error interno."},{status:500})}}let g=new i.AppRouteRouteModule({definition:{kind:s.RouteKind.APP_ROUTE,page:"/api/auth/local-login/route",pathname:"/api/auth/local-login",filename:"route",bundlePath:"app/api/auth/local-login/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\auth\\local-login\\route.ts",nextConfigOutput:"standalone",userland:n}),{workAsyncStorage:T,workUnitAsyncStorage:C,serverHooks:U}=g;function E(){return(0,a.patchFetch)({workAsyncStorage:T,workUnitAsyncStorage:C})}},96487:()=>{},78335:()=>{},98095:(e,r,t)=>{"use strict";function n(){return"mysql"===String(process.env.AUTH_MODE||process.env.NEXT_PUBLIC_AUTH_MODE||"").trim().toLowerCase()?"mysql":"firebase"}t.d(r,{f:()=>n})},50675:(e,r,t)=>{"use strict";t.d(r,{Ci:()=>c,Z2:()=>p,t7:()=>m,zj:()=>l});var n=t(23951),i=t(522);let s=null;async function a(){if(s)return s;let e=(0,n.T)(),r=(0,i.M)(),t=`SHOW COLUMNS FROM ${(0,i.j)(r.usersTable)}`,[a]=await e.query(t);return s=new Set(a.map(e=>String(e.Field||"").trim()).filter(e=>!!e))}function o(e,r){for(let t of r){let r=String(t||"").trim();if(r&&e.has(r))return r}}function u(e){if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e);let r=String(e??"").trim();if(!r)return[];if(r.startsWith("[")&&r.endsWith("]"))try{let e=JSON.parse(r);if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e)}catch{}return r.split(",").map(e=>e.trim()).filter(e=>!!e)}function l(e){let r=String(e.status||"").trim().toLowerCase();return!r||"active"===r||"enabled"===r}async function m(e){let r=String(e||"").trim().toLowerCase();if(!r)return null;let t=(0,n.T)(),s=(0,i.M)(),l=await a(),m=o(l,[s.statusColumn,"status"]),c=o(l,[s.firebaseUidColumn,"firebase_uid"]),p=o(l,[s.displayNameColumn,"display_name","name"]),d=o(l,[s.firstNameColumn,"first_name"]),S=o(l,[s.lastNameColumn,"last_name"]),f=o(l,[s.roleColumn,"role_id","role"]),_=o(l,[s.orgIdColumn,"org_id"]),A=o(l,[s.institutionIdsColumn,"institution_ids"]),g=o(l,["permissions"]),T=m?`, ${(0,i.j)(m)} AS status`:"",C=c?`, ${(0,i.j)(c)} AS firebase_uid`:"",U=p?`, ${(0,i.j)(p)} AS display_name`:"",E=d?`, ${(0,i.j)(d)} AS first_name`:"",N=S?`, ${(0,i.j)(S)} AS last_name`:"",h=f?`, ${(0,i.j)(f)} AS role_id`:"",v=_?`, ${(0,i.j)(_)} AS org_id`:"",O=A?`, ${(0,i.j)(A)} AS institution_ids`:"",y=g?`, ${(0,i.j)(g)} AS permissions`:"",w=`
    SELECT
      ${(0,i.j)(s.idColumn)} AS id,
      ${(0,i.j)(s.emailColumn)} AS email,
      ${(0,i.j)(s.passwordColumn)} AS password_hash
      ${T}
      ${C}
      ${U}
      ${E}
      ${N}
      ${h}
      ${v}
      ${O}
      ${y}
    FROM ${(0,i.j)(s.usersTable)}
    WHERE ${(0,i.j)(s.emailColumn)} = ?
    LIMIT 1
  `,[R]=await t.query(w,[r]);if(!R.length)return null;let $=R[0];return{id:String($.id??""),email:String($.email??r).trim().toLowerCase(),passwordHash:String($.password_hash??""),status:null==$.status?null:String($.status),firebaseUid:null==$.firebase_uid?null:String($.firebase_uid),displayName:null==$.display_name?null:String($.display_name),firstName:null==$.first_name?null:String($.first_name),lastName:null==$.last_name?null:String($.last_name),roleId:null==$.role_id?null:String($.role_id),orgId:null==$.org_id?null:String($.org_id),institutionIds:u($.institution_ids),permissions:u($.permissions)}}async function c(e,r){var t;let s=String(e||"").trim().toLowerCase();if(!s||!r)return!1;let o=(0,i.M)(),u=await a(),l=(0,n.T)(),m=(t=o.updatedAtColumn)&&u.has(t)?`, ${(0,i.j)(o.updatedAtColumn)} = UTC_TIMESTAMP()`:"",c=`
    UPDATE ${(0,i.j)(o.usersTable)}
    SET ${(0,i.j)(o.passwordColumn)} = ?${m}
    WHERE ${(0,i.j)(o.emailColumn)} = ?
    LIMIT 1
  `,[p]=await l.query(c,[r,s]);return Number(p.affectedRows||0)>0}async function p(e){var r;let t=String(e.email||"").trim().toLowerCase(),s=String(e.passwordHash||"").trim();if(!t||!s)throw Error("email and passwordHash are required");let u=(0,n.T)(),l=(0,i.M)(),m=await a(),c=o(m,[l.roleColumn,"role_id","role"]),p=function(e,r){let t=[];for(let n of r)n.column&&e.has(n.column)&&t.push({column:n.column,value:n.value});return t}(m,[{column:l.emailColumn,value:t},{column:l.passwordColumn,value:s},{column:l.statusColumn,value:e.status||"pending"},{column:l.firebaseUidColumn,value:e.firebaseUid||null},{column:l.firstNameColumn,value:e.firstName||null},{column:l.lastNameColumn,value:e.lastName||null},{column:l.displayNameColumn,value:e.displayName||null},{column:l.phoneColumn,value:e.phone||null},{column:c,value:e.role||null},{column:l.orgIdColumn,value:e.orgId||null},{column:l.institutionIdsColumn,value:e.institutionIds&&e.institutionIds.length?JSON.stringify(e.institutionIds):JSON.stringify([])}]);if(!p.length)throw Error("No writable columns found in users table.");let d=p.filter(e=>e.column!==l.emailColumn&&e.column!==l.createdAtColumn);(r=l.updatedAtColumn)&&m.has(r)&&d.push({column:l.updatedAtColumn,value:null});let S=p.map(e=>(0,i.j)(e.column)).join(", "),f=p.map(()=>"?").join(", "),_=d.map(e=>e.column===l.updatedAtColumn?`${(0,i.j)(e.column)} = UTC_TIMESTAMP()`:`${(0,i.j)(e.column)} = VALUES(${(0,i.j)(e.column)})`).join(", "),A=`
    INSERT INTO ${(0,i.j)(l.usersTable)} (${S})
    VALUES (${f})
    ON DUPLICATE KEY UPDATE ${_}
  `,g=p.map(e=>e.column===l.updatedAtColumn?void 0:e.value);await u.query(A,g)}},23951:(e,r,t)=>{"use strict";t.d(r,{T:()=>u});var n=t(60820);let i=null;function s(e){for(let r of e){let e=process.env[r];if(e&&String(e).trim())return String(e).trim()}}function a(e,r){let t=s(e);if(!t)throw Error(`Missing ${r}. Set one of: ${e.join(", ")}`);return t}function o(e,r){if(!e)return r;let t=Number(e);return Number.isFinite(t)?t:r}function u(){if(i)return i;let e=a(["AUTH_DB_HOST","DB_HOST"],"database host"),r=a(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),t=a(["AUTH_DB_PASSWORD","DB_PASSWORD"],"database password"),u=a(["AUTH_DB_NAME","DB_DATABASE"],"database name"),l=o(s(["AUTH_DB_PORT","DB_PORT"]),3306),m=o(s(["AUTH_DB_POOL_SIZE","DB_POOL_SIZE"]),10);return i=n.createPool({host:e,port:l,user:r,password:t,database:u,waitForConnections:!0,connectionLimit:m,queueLimit:0,charset:"utf8mb4"})}},522:(e,r,t)=>{"use strict";function n(e,r){let t=String(e||r||"").trim();if(!t)return"";if(!/^[A-Za-z0-9_]+$/.test(t))throw Error(`Invalid SQL identifier: ${t}`);return t}function i(e,r){let t=String(e||r||"").trim();if(t&&"-"!==t)return n(t)}function s(e){return`\`${n(e)}\``}function a(){return{usersTable:n(process.env.AUTH_USERS_TABLE,"users"),passwordResetsTable:n(process.env.AUTH_PASSWORD_RESETS_TABLE,"auth_password_resets"),idColumn:n(process.env.AUTH_USERS_ID_COLUMN,"id"),emailColumn:n(process.env.AUTH_USERS_EMAIL_COLUMN,"email"),passwordColumn:n(process.env.AUTH_USERS_PASSWORD_COLUMN,"password"),statusColumn:i(process.env.AUTH_USERS_STATUS_COLUMN,"status"),firebaseUidColumn:i(process.env.AUTH_USERS_FIREBASE_UID_COLUMN,"firebase_uid"),firstNameColumn:i(process.env.AUTH_USERS_FIRST_NAME_COLUMN,"first_name"),lastNameColumn:i(process.env.AUTH_USERS_LAST_NAME_COLUMN,"last_name"),displayNameColumn:i(process.env.AUTH_USERS_DISPLAY_NAME_COLUMN,"display_name"),phoneColumn:i(process.env.AUTH_USERS_PHONE_COLUMN,"phone"),roleColumn:i(process.env.AUTH_USERS_ROLE_COLUMN,"role"),orgIdColumn:i(process.env.AUTH_USERS_ORG_ID_COLUMN,"org_id"),institutionIdsColumn:i(process.env.AUTH_USERS_INSTITUTION_IDS_COLUMN,"institution_ids"),createdAtColumn:i(process.env.AUTH_USERS_CREATED_AT_COLUMN,"created_at"),updatedAtColumn:i(process.env.AUTH_USERS_UPDATED_AT_COLUMN,"updated_at")}}t.d(r,{M:()=>a,j:()=>s})},89249:(e,r,t)=>{"use strict";t.d(r,{$G:()=>S,C0:()=>f,CA:()=>l,Q7:()=>c,zP:()=>d});var n=t(77598),i=t.n(n);let s="omr_local_session";function a(e){return(Buffer.isBuffer(e)?e:Buffer.from(e)).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function o(e){let r=String(e||"").replace(/-/g,"+").replace(/_/g,"/"),t=r.length%4==0?"":"=".repeat(4-r.length%4);return Buffer.from(r+t,"base64")}function u(){return String(process.env.AUTH_SESSION_SECRET||process.env.NEXTAUTH_SECRET||process.env.AUTH_DB_PASSWORD||"").trim()||"omr-local-session-dev-secret-change-me"}function l(){return String(process.env.AUTH_SESSION_COOKIE_NAME||s).trim()||s}function m(){let e=Number(process.env.AUTH_SESSION_TTL_HOURS||168);return Math.round(3600*(Number.isFinite(e)&&e>0?e:168))}function c(e){let r=Math.floor(Date.now()/1e3),t={v:1,iat:r,exp:r+m(),user:e},n=a(JSON.stringify({alg:"HS256",typ:"JWT"})),s=a(JSON.stringify(t)),o=`${n}.${s}`,l=a(i().createHmac("sha256",u()).update(o).digest());return`${o}.${l}`}function p(e){try{return JSON.parse(e)}catch{return null}}function d(e){let r=String(e||"").trim().split(".");if(3!==r.length)return null;let[t,n,s]=r;if(!t||!n||!s)return null;let l=`${t}.${n}`,m=a(i().createHmac("sha256",u()).update(l).digest()),c=Buffer.from(m),d=Buffer.from(s);if(c.length!==d.length||!i().timingSafeEqual(c,d))return null;let S=p(o(t).toString("utf8"));if(!S||"HS256"!==S.alg||"JWT"!==S.typ)return null;let f=p(o(n).toString("utf8"));if(!f||1!==f.v)return null;let _=Math.floor(Date.now()/1e3);if(!Number.isFinite(f.exp)||f.exp<=_)return null;let A=f.user;return A&&String(A.id||"").trim()&&String(A.email||"").trim()?f:null}function S(e,r){e.cookies.set(l(),r,{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:m()})}function f(e){e.cookies.set(l(),"",{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:0})}}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),n=r.X(0,[1989,5452,820,5658,4926],()=>t(63184));module.exports=n})();