"use strict";(()=>{var e={};e.id=7362,e.ids=[7362],e.modules={53524:e=>{e.exports=require("@prisma/client")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},84770:e=>{e.exports=require("crypto")},21126:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>y,requestAsyncStorage:()=>x,routeModule:()=>m,serverHooks:()=>g,staticGenerationAsyncStorage:()=>w});var s={};r.r(s),r.d(s,{POST:()=>c,dynamic:()=>p});var n=r(49303),a=r(88716),o=r(60670),i=r(87070),u=r(72331),d=r(98691),l=r(90455);let p="force-dynamic";async function c(e){try{let t;try{t=await e.json()}catch(e){return i.NextResponse.json({error:"Invalid JSON body"},{status:400})}let{username:r,password:s}=t||{};if("string"==typeof r&&(r=r.trim()),"string"==typeof s&&(s=s.trim()),!r)return i.NextResponse.json({error:"Username is required"},{status:400});let n=await u._.user.findUnique({where:{username:r}});if(!n)return i.NextResponse.json({error:"User not found. Please register."},{status:404});if(n.password){if(!s)return i.NextResponse.json({error:"Password required"},{status:401});let e=!1;try{e=await d.ZP.compare(s,n.password)}catch(t){e=!1}if(!e&&n.password===s){e=!0;try{let e=await d.ZP.hash(s,10);await u._.user.update({where:{id:n.id},data:{password:e}})}catch(e){}}if(!e)return i.NextResponse.json({error:"Invalid password"},{status:401})}let a=crypto.randomUUID();return await u._.user.update({where:{id:n.id},data:{sessionToken:a}}),await (0,l.KY)(n.id,n.role,a),i.NextResponse.json(n)}catch(e){return console.error("[Login Error] Unexpected error:",e),i.NextResponse.json({error:e.message||"Internal Server Error",details:String(e)},{status:500})}}let m=new n.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/user/login/route",pathname:"/api/user/login",filename:"route",bundlePath:"app/api/user/login/route"},resolvedPagePath:"C:\\Users\\MSI\\Downloads\\film\\app\\api\\user\\login\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:x,staticGenerationAsyncStorage:w,serverHooks:g}=m,f="/api/user/login/route";function y(){return(0,o.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:w})}},90455:(e,t,r)=>{r.d(t,{Gg:()=>c,KY:()=>p,Ov:()=>m});var s=r(86890),n=r(41463),a=r(71615),o=r(72331);let i=process.env.JWT_SECRET_KEY||"rahasia-super-aman-ganti-di-env",u=new TextEncoder().encode(i);async function d(e){return await new s.N(e).setProtectedHeader({alg:"HS256"}).setIssuedAt().setExpirationTime("24h").sign(u)}async function l(e){try{let{payload:t}=await (0,n._)(e,u);return t}catch(e){return null}}async function p(e,t,r){let s=await d({userId:e,role:t,sessionToken:r}),n=new Date(Date.now()+864e5);(0,a.cookies)().set("admin_session",s,{expires:n,httpOnly:!0,secure:!0,sameSite:"lax",path:"/"})}async function c(){let e=a.cookies().get("admin_session")?.value;if(!e)return null;let t=await l(e);if(!t||!t.userId||!t.sessionToken)return null;let r=await o._.user.findUnique({where:{id:t.userId},select:{sessionToken:!0}});return r&&r.sessionToken===t.sessionToken?t:null}async function m(){(0,a.cookies)().delete("admin_session")}},72331:(e,t,r)=>{r.d(t,{_:()=>n});var s=r(53524);let n=global.prisma||new s.PrismaClient}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8948,5972,8691,3112],()=>r(21126));module.exports=s})();