"use strict";(()=>{var e={};e.id=2998,e.ids=[2998],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,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},55896:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>S,routeModule:()=>g});var n={};t.r(n),t.d(n,{default:()=>E});var s=t(89947),i=t(2706),a=t(96762),o=t(69842),l=t(29021),u=t.n(l),c=t(67619),_=t(48786),d=t(68829),f=t(89159);async function p({userId:e,res:r,csrf:t}){try{let n=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!n)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;let s=await (0,_.A)("SELECT * FROM users WHERE id=?",[e]);u().unlinkSync(`${n}/${t}`);let i=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),a={id:s[0].id,stripe_id:s[0].stripe_id||"",first_name:s[0].first_name,last_name:s[0].last_name,email:s[0].email,social_id:s[0].social_id,image:s[0].image,image_thumbnail:s[0].image_thumbnail,verification_status:s[0].verification_status,social_login:s[0].social_login,social_platform:s[0].social_platform,csrf_k:i,logged_in_status:!0,date:Date.now()},o=(0,d.default)({data:JSON.stringify(a)});u().writeFileSync(`${n}/${i}`,JSON.stringify(a));let{keyCookieName:l,csrfCookieName:c}=(0,f.A)();return r.setHeader("Set-Cookie",[`${l}=${o};samesite=strict;path=/;HttpOnly=true;Secure=true`,`${c}=${i};samesite=strict;path=/;HttpOnly=true;Secure=true`,"user_refresh=1"]),a}catch(r){return(0,c.default)({component:"reAuthUser",message:r.message,user:{id:e}}),null}}async function E(e,r){"POST"!==e.method&&r.json({msg:"Failed!"});let t=await (0,o.A)(e,r,!0);if(!t){console.log("No user Found"),r.redirect(307,"/logout");return}let n=await p({userId:t.id,res:r,csrf:t.csrf_k}),s={status:!!n,csrf:n?.csrf_k,user:n};r.json(s)}let S=(0,a.M)(n,"default"),m=(0,a.M)(n,"config"),g=new s.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/reAuthenticateUser",pathname:"/api/reAuthenticateUser",bundlePath:"",filename:""},userland:n})},69842:(e,r,t)=>{t.d(r,{A:()=>l});var n=t(48786),s=t(95969),i=t(29021),a=t.n(i),o=t(89159);async function l(e,r,t){let{keyCookieName:i,csrfCookieName:l}=(0,o.A)();if(!e.cookies?.[i]?.match(/./))return null;let u=(0,s.A)({encryptedString:e.cookies[i]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(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(t&&!a().existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,n.A)(`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}},89159:(e,r,t)=>{t.d(r,{A:()=>n});function n(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",n=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",i=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),i&&(a+=`${i}_`),a+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),i&&(o+=`${i}_`),o+=n;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),i&&(l+=`${i}_`),{keyCookieName:a,csrfCookieName:o,oneTimeCodeName:l+=s}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>i});var n=t(29021),s=t.n(n);async function i({user:e,message:r,component:t,noMail:n,req:i}){let a=new Date,o=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],r=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||i.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),i?.url&&(n+=` URL: ${i.url}`),i?.body&&(n+=` Request Body: ${JSON.stringify(i.body,null,4)}`),o&&(n+=` IP: ${o}`),n+=` Date: ${a.toDateString()} ========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let l=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",n),s().appendFileSync("./.tmp/error.log",` ${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(55511),s=t(79428);function i({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!i?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,n.scryptSync)(i,a,o),u=s.Buffer.alloc(16,0),c=(0,n.createDecipheriv)("aes-192-cbc",l,u);try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,t)=>{t.r(r),t.d(r,{default:()=>i});var n=t(55511),s=t(79428);function i({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let i=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!i?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let l=(0,n.scryptSync)(i,a,o),u=s.Buffer.alloc(16,0),c=(0,n.createCipheriv)("aes-192-cbc",l,u);try{let r=c.update(e,"utf8","hex");return r+=c.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>n});async function n(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}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 t}});var t=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,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=55896);module.exports=t})();