"use strict";(()=>{var e={};e.id=7258,e.ids=[7258],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},45310:(e,r,s)=>{s.r(r),s.d(r,{config:()=>l,default:()=>d,routeModule:()=>c});var t={};s.r(t),s.d(t,{default:()=>_});var i=s(89947),n=s(2706),a=s(96762),u=s(48786),o=s(69842);async function _(e,r){if("GET"!==e.method)return r.json({msg:"Failed!"});let s=await (0,o.A)(e,r);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=await (0,u.A)(` SELECT user_users.user_id,user_users.database_access,user_users.user_id,user_users.user_priviledge,users.first_name,users.last_name,users.email,users.image_thumbnail FROM user_users JOIN users ON user_users.user_id=users.id WHERE user_users.invited_user_id='${s.id}' `),i=[];if(t&&t[0])for(let e=0;e`db_slug='${e}'`).join(" OR ")}) AND user_id=${n}`);for(let e=0;e{s.d(r,{A:()=>o});var t=s(48786),i=s(95969),n=s(29021),a=s.n(n),u=s(89159);async function o(e,r,s){try{let{keyCookieName:n,csrfCookieName:o}=(0,u.A)();if(!e.cookies?.[n]?.match(/./))throw Error("Request Cookies not Found!");let _=(0,i.A)({encryptedString:e.cookies[n]});if(!_)throw Error("Couldn't decrypt auth cookie!");let d=JSON.parse(_);if(!d.csrf_k)throw Error("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let l=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!l)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(s&&!a().existsSync(`${l}/${d.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==d.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(d?.date&&Date.now()-d.date>6048e5)throw Error("Key expired!");return d}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.message}`),null}}},89159:(e,r,s)=>{s.d(r,{A:()=>t});function t(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=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),a+=s;let u=r;e?.userId&&(u+=`user_${e.userId}_`),n&&(u+=`${n}_`),u+=t;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),{keyCookieName:a,csrfCookieName:u,oneTimeCodeName:o+=i}}},95969:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(55511),i=s(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=s||process.env.DSQL_ENCRYPTION_SALT,u=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=(0,t.scryptSync)(n,a,u),_=i.Buffer.alloc(16,0),d=(0,t.createDecipheriv)("aes-192-cbc",o,_);try{let r=d.update(e,"hex","utf8");return r+=d.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,s)=>{s.d(r,{A:()=>t});async function t(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=r(r.s=45310);module.exports=s})();