"use strict";(()=>{var e={};e.id=519,e.ids=[519],e.modules={3524:e=>{e.exports=require("@prisma/client")},7096:e=>{e.exports=require("bcrypt")},9344:e=>{e.exports=require("jsonwebtoken")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6249:(e,r)=>{Object.defineProperty(r,"l",{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}}})},1833:(e,r,t)=>{t.r(r),t.d(r,{config:()=>c,default:()=>l,routeModule:()=>p});var a={};t.r(a),t.d(a,{default:()=>d});var s=t(1802),n=t(7153),u=t(6249),i=t(3481),o=t(1026);async function d(e,r){if("POST"!==e.method)return r.status(405).json({success:!1,error:"Method not allowed"});try{let{username:t,password:a,email:s}=e.body;if(!t||!a)return r.status(400).json({success:!1,error:"Username and password are required"});if(t.length<3)return r.status(400).json({success:!1,error:"Username must be at least 3 characters"});if(a.length<6)return r.status(400).json({success:!1,error:"Password must be at least 6 characters"});if(await i.K.getUserByUsername(t))return r.status(409).json({success:!1,error:"Username already taken"});let n=await i.K.createUser(t,a,s),u=(0,o.RA)(n.id);return r.setHeader("Set-Cookie",`token=${u}; HttpOnly; Path=/; Max-Age=604800; SameSite=Strict`),r.status(201).json({success:!0,data:{user:{id:n.id,username:n.username,avatarUrl:n.avatarUrl,role:n.role,status:n.status},token:u}})}catch(e){return console.error("Registration error:",e),r.status(500).json({success:!1,error:"Registration failed"})}}let l=(0,u.l)(a,"default"),c=(0,u.l)(a,"config"),p=new s.PagesAPIRouteModule({definition:{kind:n.x.PAGES_API,page:"/api/v1/auth/register",pathname:"/api/v1/auth/register",bundlePath:"",filename:""},userland:a})},3481:(e,r,t)=>{t.d(r,{K:()=>n});var a=t(1450),s=t(1026);let n={async getUserById(e){let r=await a.Z.user.findUnique({where:{id:e},select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}});return r?{...r,role:r.role,createdAt:r.createdAt.toISOString(),lastLogin:r.lastLogin?.toISOString()||new Date().toISOString(),avatarUrl:r.avatarUrl||""}:null},getUserByUsername:async e=>a.Z.user.findUnique({where:{username:e}}),async createUser(e,r,t){let n=await (0,s.c_)(r),u=`https://api.dicebear.com/7.x/avataaars/svg?seed=${e}`;return a.Z.user.create({data:{username:e,password:n,avatarUrl:u,role:"CREATOR",status:"ACTIVE"}})},async authenticateUser(e,r){let t=await this.getUserByUsername(e);return t&&t.password&&await (0,s.Gv)(r,t.password)?(await a.Z.user.update({where:{id:t.id},data:{lastLogin:new Date}}),{id:t.id,username:t.username,avatarUrl:t.avatarUrl||"",role:t.role,status:t.status,createdAt:t.createdAt.toISOString(),lastLogin:new Date().toISOString()}):null},getAllUsers:async()=>a.Z.user.findMany({orderBy:{createdAt:"desc"}}),updateUser:async(e,r)=>a.Z.user.update({where:{id:e},data:{username:r.username,avatarUrl:r.avatarUrl}}),updateUserRole:async(e,r)=>a.Z.user.update({where:{id:e},data:{role:r}}),async toggleUserStatus(e){let r=await a.Z.user.findUnique({where:{id:e}});if(!r)throw Error("User not found");let t="ACTIVE"===r.status?"BANNED":"ACTIVE";return a.Z.user.update({where:{id:e},data:{status:t}})}}},1026:(e,r,t)=>{t.d(r,{Gv:()=>d,RA:()=>l,WX:()=>c,c_:()=>o});var a=t(7096),s=t.n(a),n=t(9344),u=t.n(n);function i(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}async function o(e){return s().hash(e,10)}async function d(e,r){return s().compare(e,r)}function l(e){return u().sign({userId:e},i(),{expiresIn:"7d"})}function c(e){try{return u().verify(e,i())}catch(e){return null}}},1450:(e,r,t)=>{t.d(r,{Z:()=>s});var a=t(3524);let s=globalThis.prisma??new a.PrismaClient},7153:(e,r)=>{var t;Object.defineProperty(r,"x",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(t||(t={}))},1802:(e,r,t)=>{e.exports=t(145)}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=1833);module.exports=t})();