exports.id=4032,exports.ids=[4032],exports.modules={28303:e=>{function t(e){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=28303,e.exports=t},96487:()=>{},78335:()=>{},98095:(e,t,r)=>{"use strict";function n(){return"mysql"===String(process.env.AUTH_MODE||process.env.NEXT_PUBLIC_AUTH_MODE||"").trim().toLowerCase()?"mysql":"firebase"}r.d(t,{f:()=>n})},70357:(e,t,r)=>{"use strict";r.d(t,{x:()=>s});var n=r(98721);let i=null;async function s(e){let t=String(e.to||"").trim().toLowerCase();if(!t)return;if("true"===String(process.env.AUTH_SMTP_DRY_RUN||"").trim().toLowerCase()){console.info("[AUTH_SMTP_DRY_RUN]",{to:t,subject:e.subject,text:e.text});return}let r=function(){if(i)return i;let e=String(process.env.AUTH_SMTP_HOST||"").trim(),t=Number(process.env.AUTH_SMTP_PORT||587),r="true"===String(process.env.AUTH_SMTP_SECURE||"").trim().toLowerCase(),s=String(process.env.AUTH_SMTP_USER||"").trim(),a=String(process.env.AUTH_SMTP_PASS||"").trim();if(!e||!t||!s||!a)throw Error("Missing SMTP config. Set AUTH_SMTP_HOST, AUTH_SMTP_PORT, AUTH_SMTP_USER, AUTH_SMTP_PASS");return i=n.createTransport({host:e,port:t,secure:r,auth:{user:s,pass:a}})}();await r.sendMail({from:String(process.env.AUTH_MAIL_FROM||"").trim()||"OMR SEG <no-reply@roregar.cl>",to:t,subject:e.subject,text:e.text,html:e.html||void 0})}},50675:(e,t,r)=>{"use strict";r.d(t,{Ci:()=>m,Z2:()=>S,t7:()=>_,zj:()=>l});var n=r(23951),i=r(522);let s=null;async function a(){if(s)return s;let e=(0,n.T)(),t=(0,i.M)(),r=`SHOW COLUMNS FROM ${(0,i.j)(t.usersTable)}`,[a]=await e.query(r);return s=new Set(a.map(e=>String(e.Field||"").trim()).filter(e=>!!e))}function o(e,t){for(let r of t){let t=String(r||"").trim();if(t&&e.has(t))return t}}function u(e){if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e);let t=String(e??"").trim();if(!t)return[];if(t.startsWith("[")&&t.endsWith("]"))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(e=>!!e)}catch{}return t.split(",").map(e=>e.trim()).filter(e=>!!e)}function l(e){let t=String(e.status||"").trim().toLowerCase();return!t||"active"===t||"enabled"===t}async function _(e){let t=String(e||"").trim().toLowerCase();if(!t)return null;let r=(0,n.T)(),s=(0,i.M)(),l=await a(),_=o(l,[s.statusColumn,"status"]),m=o(l,[s.firebaseUidColumn,"firebase_uid"]),S=o(l,[s.displayNameColumn,"display_name","name"]),T=o(l,[s.firstNameColumn,"first_name"]),d=o(l,[s.lastNameColumn,"last_name"]),E=o(l,[s.roleColumn,"role_id","role"]),A=o(l,[s.orgIdColumn,"org_id"]),c=o(l,[s.institutionIdsColumn,"institution_ids"]),U=o(l,["permissions"]),f=_?`, ${(0,i.j)(_)} AS status`:"",p=m?`, ${(0,i.j)(m)} AS firebase_uid`:"",C=S?`, ${(0,i.j)(S)} AS display_name`:"",N=T?`, ${(0,i.j)(T)} AS first_name`:"",M=d?`, ${(0,i.j)(d)} AS last_name`:"",R=E?`, ${(0,i.j)(E)} AS role_id`:"",L=A?`, ${(0,i.j)(A)} AS org_id`:"",O=c?`, ${(0,i.j)(c)} AS institution_ids`:"",I=U?`, ${(0,i.j)(U)} AS permissions`:"",g=`
    SELECT
      ${(0,i.j)(s.idColumn)} AS id,
      ${(0,i.j)(s.emailColumn)} AS email,
      ${(0,i.j)(s.passwordColumn)} AS password_hash
      ${f}
      ${p}
      ${C}
      ${N}
      ${M}
      ${R}
      ${L}
      ${O}
      ${I}
    FROM ${(0,i.j)(s.usersTable)}
    WHERE ${(0,i.j)(s.emailColumn)} = ?
    LIMIT 1
  `,[w]=await r.query(g,[t]);if(!w.length)return null;let H=w[0];return{id:String(H.id??""),email:String(H.email??t).trim().toLowerCase(),passwordHash:String(H.password_hash??""),status:null==H.status?null:String(H.status),firebaseUid:null==H.firebase_uid?null:String(H.firebase_uid),displayName:null==H.display_name?null:String(H.display_name),firstName:null==H.first_name?null:String(H.first_name),lastName:null==H.last_name?null:String(H.last_name),roleId:null==H.role_id?null:String(H.role_id),orgId:null==H.org_id?null:String(H.org_id),institutionIds:u(H.institution_ids),permissions:u(H.permissions)}}async function m(e,t){var r;let s=String(e||"").trim().toLowerCase();if(!s||!t)return!1;let o=(0,i.M)(),u=await a(),l=(0,n.T)(),_=(r=o.updatedAtColumn)&&u.has(r)?`, ${(0,i.j)(o.updatedAtColumn)} = UTC_TIMESTAMP()`:"",m=`
    UPDATE ${(0,i.j)(o.usersTable)}
    SET ${(0,i.j)(o.passwordColumn)} = ?${_}
    WHERE ${(0,i.j)(o.emailColumn)} = ?
    LIMIT 1
  `,[S]=await l.query(m,[t,s]);return Number(S.affectedRows||0)>0}async function S(e){var t;let r=String(e.email||"").trim().toLowerCase(),s=String(e.passwordHash||"").trim();if(!r||!s)throw Error("email and passwordHash are required");let u=(0,n.T)(),l=(0,i.M)(),_=await a(),m=o(_,[l.roleColumn,"role_id","role"]),S=function(e,t){let r=[];for(let n of t)n.column&&e.has(n.column)&&r.push({column:n.column,value:n.value});return r}(_,[{column:l.emailColumn,value:r},{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:m,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(!S.length)throw Error("No writable columns found in users table.");let T=S.filter(e=>e.column!==l.emailColumn&&e.column!==l.createdAtColumn);(t=l.updatedAtColumn)&&_.has(t)&&T.push({column:l.updatedAtColumn,value:null});let d=S.map(e=>(0,i.j)(e.column)).join(", "),E=S.map(()=>"?").join(", "),A=T.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(", "),c=`
    INSERT INTO ${(0,i.j)(l.usersTable)} (${d})
    VALUES (${E})
    ON DUPLICATE KEY UPDATE ${A}
  `,U=S.map(e=>e.column===l.updatedAtColumn?void 0:e.value);await u.query(c,U)}},23951:(e,t,r)=>{"use strict";r.d(t,{T:()=>u});var n=r(60820);let i=null;function s(e){for(let t of e){let e=process.env[t];if(e&&String(e).trim())return String(e).trim()}}function a(e,t){let r=s(e);if(!r)throw Error(`Missing ${t}. Set one of: ${e.join(", ")}`);return r}function o(e,t){if(!e)return t;let r=Number(e);return Number.isFinite(r)?r:t}function u(){if(i)return i;let e=a(["AUTH_DB_HOST","DB_HOST"],"database host"),t=a(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),r=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),_=o(s(["AUTH_DB_POOL_SIZE","DB_POOL_SIZE"]),10);return i=n.createPool({host:e,port:l,user:t,password:r,database:u,waitForConnections:!0,connectionLimit:_,queueLimit:0,charset:"utf8mb4"})}},42770:(e,t,r)=>{"use strict";r.d(t,{G8:()=>_,Vo:()=>l});var n=r(77598),i=r.n(n),s=r(23951),a=r(522);function o(e){return i().createHash("sha256").update(e).digest("hex")}async function u(){let e=(0,s.T)(),t=(0,a.M)(),r=`
    CREATE TABLE IF NOT EXISTS ${(0,a.j)(t.passwordResetsTable)} (
      id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
      email VARCHAR(191) NOT NULL,
      token_hash CHAR(64) NOT NULL,
      expires_at DATETIME NOT NULL,
      used_at DATETIME NULL,
      created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (id),
      KEY idx_email (email),
      KEY idx_token_hash (token_hash),
      KEY idx_expires_at (expires_at)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  `;await e.query(r)}async function l(e){let t=String(e||"").trim().toLowerCase(),r=function(){let e=Number(process.env.AUTH_RESET_TOKEN_TTL_MINUTES||30);return Number.isFinite(e)&&e>0?e:30}(),n=new Date(Date.now()+6e4*r),l=i().randomBytes(function(){let e=Number(process.env.AUTH_RESET_TOKEN_BYTES||32);return Number.isFinite(e)&&e>=16?e:32}()).toString("hex"),_=o(l);await u();let m=(0,s.T)(),S=(0,a.M)(),T=`
    DELETE FROM ${(0,a.j)(S.passwordResetsTable)}
    WHERE email = ?
      OR expires_at < UTC_TIMESTAMP()
      OR used_at IS NOT NULL
  `;await m.query(T,[t]);let d=`
    INSERT INTO ${(0,a.j)(S.passwordResetsTable)}
      (email, token_hash, expires_at)
    VALUES (?, ?, ?)
  `;return await m.query(d,[t,_,n]),{token:l,expiresAt:n}}async function _(e,t){let r=String(e||"").trim().toLowerCase(),n=String(t||"").trim();if(!r||!n)return!1;await u();let i=(0,s.T)(),l=(0,a.M)(),_=o(n),m=`
    SELECT id
    FROM ${(0,a.j)(l.passwordResetsTable)}
    WHERE email = ?
      AND token_hash = ?
      AND used_at IS NULL
      AND expires_at >= UTC_TIMESTAMP()
    ORDER BY id DESC
    LIMIT 1
  `,[S]=await i.query(m,[r,_]);if(!S.length)return!1;let T=Number(S[0].id||0);if(!T)return!1;let d=`
    UPDATE ${(0,a.j)(l.passwordResetsTable)}
    SET used_at = UTC_TIMESTAMP()
    WHERE id = ?
      AND used_at IS NULL
    LIMIT 1
  `,[E]=await i.query(d,[T]);return 1===Number(E.affectedRows||0)}},522:(e,t,r)=>{"use strict";function n(e,t){let r=String(e||t||"").trim();if(!r)return"";if(!/^[A-Za-z0-9_]+$/.test(r))throw Error(`Invalid SQL identifier: ${r}`);return r}function i(e,t){let r=String(e||t||"").trim();if(r&&"-"!==r)return n(r)}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")}}r.d(t,{M:()=>a,j:()=>s})}};