"use strict";(()=>{var e={};e.id=294,e.ids=[294],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},98397:(e,r,s)=>{s.r(r),s.d(r,{config:()=>S,default:()=>E,routeModule:()=>v});var t={};s.r(t),s.d(t,{default:()=>f});var i=s(89947),a=s(2706),l=s(96762),n=s(51348),o=s.n(n),u=s(6420),d=s.n(u),c=s(47670),_=s.n(c);s(29021),s(33873);let{execSync:p}=s(79646);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await d()(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{userObject:t,database_access:i,user_priviledge:a,db_tables:l,inv_user_id:n}=e.body,u=await o()("UPDATE user_users SET database_access = ? ,user_priviledge = ? WHERE user_id = ? AND email = ?",[i,a,s.id,t.email]),c=l.split("|");await o()(`DELETE FROM delegated_user_tables WHERE root_user_id='${s.id}' AND delegated_user_id='${n}'`);for(let e=0;e{s(81630);let t=s(51348),i=s(72835),a=s(29021),l=s(31341);async function n(e,r,s,n){let{keyCookieName:o,csrfCookieName:u}=l();if(!e.cookies?.[o]?.match(/./))return null;let d=i({encryptedString:e.cookies[o]});if(!d)return null;let c=JSON.parse(d);if(!c.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!a.existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!s){let e=await t(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=n},31341:e=>{e.exports=function(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),i&&(a+=`${i}_`),a+=s;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),i&&(l+=`${i}_`),{keyCookieName:a,csrfCookieName:l+=t}}},72835:(e,r,s)=>{let{scryptSync:t,createDecipheriv:i}=s(55511),{Buffer:a}=s(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:s})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let l=r||process.env.DSQL_ENCRYPTION_PASSWORD,n=s||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!l?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!n?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=i("aes-192-cbc",t(l,n,o),a.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[4050],()=>s(98397));module.exports=t})();