8 lines
5.1 KiB
JavaScript
8 lines
5.1 KiB
JavaScript
"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),o=s(48786),u=s(69842);async function _(e,r){if("GET"!==e.method)return r.json({msg:"Failed!"});let s=await (0,u.A)(e,r);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=await (0,o.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<t.length;e++){let r=t[e],{database_access:s,user_id:n,user_priviledge:a}=r;if(!s?.match(/./))continue;let u=await (0,o.A)(`SELECT * FROM user_databases WHERE (${s.split("|").map(e=>`db_slug='${e}'`).join(" OR ")}) AND user_id=${n}`);for(let e=0;e<u.length;e++){let s=u[e];i.push({id:s.id,user_id:r.user_id,first_name:r.first_name,last_name:r.last_name,email:r.email,image_thumbnail:r.image_thumbnail,db_name:s.db_name,db_slug:s.db_slug,db_full_name:s.db_full_name,db_image:s.db_image,db_description:s.db_description,date_created:s.date_created,user_priviledge:a})}}r.json({success:!0,databases:i})}let d=(0,a.M)(t,"default"),l=(0,a.M)(t,"config"),c=new i.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/getDelegatedDatabases",pathname:"/api/getDelegatedDatabases",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>u});var t=s(48786),i=s(95969),n=s(29021),a=s.n(n),o=s(89159);async function u(e,r,s){try{let{keyCookieName:n,csrfCookieName:u}=(0,o.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 console.log("req.headers",e.headers),console.log("userObject",d),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(e){return console.log(`userAuth Error: ${e.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 o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=t;let u=r;return e?.userId&&(u+=`user_${e.userId}_`),n&&(u+=`${n}_`),{keyCookieName:a,csrfCookieName:o,oneTimeCodeName:u+=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,o=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 u=(0,t.scryptSync)(n,a,o),_=i.Buffer.alloc(16,0),d=(0,t.createDecipheriv)("aes-192-cbc",u,_);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})(); |