"use strict";(()=>{var e={};e.id=240,e.ids=[240],e.modules={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")},81658:(e,o,t)=>{t.r(o),t.d(o,{originalPathname:()=>O,patchFetch:()=>m,requestAsyncStorage:()=>T,routeModule:()=>h,serverHooks:()=>E,staticGenerationAsyncStorage:()=>g});var r={};t.r(r),t.d(r,{OPTIONS:()=>p,POST:()=>d,dynamic:()=>c});var n=t(49303),s=t(88716),a=t(60670),i=t(87070);let c="force-dynamic",l="https://bsky.social";async function u(e){try{let o=`${e}/oauth/token`;return(await fetch(o,{method:"HEAD",headers:{Accept:"*/*"}})).headers.get("DPoP-Nonce")}catch(e){return console.error("Error getting nonce:",e),null}}async function d(e){try{let{code:o,codeVerifier:t,dpopToken:r,pdsEndpoint:n,originalPdsEndpoint:s}=await e.json();console.log("[TOKEN ROUTE] Request parameters:",{code:o?o.substring(0,6)+"...":"none",codeVerifier:t?t.substring(0,6)+"...":"none",pdsEndpoint:n,originalPdsEndpoint:s,dpopTokenProvided:!!r});let a=n||l;if(n?n.includes("bsky.network")?(console.log(`[TOKEN ROUTE] Using bsky.social for bsky.network PDS: ${n}`),a=l):n.includes("bsky.social")?console.log("[TOKEN ROUTE] Using bsky.social endpoint directly"):console.log(`[TOKEN ROUTE] Using third-party PDS's own endpoint for token exchange: ${n}`):(console.log(`[TOKEN ROUTE] No PDS endpoint provided, using default: ${l}`),a=l),!o||!t||!r){let e=[];return o||e.push("code"),t||e.push("codeVerifier"),r||e.push("dpopToken"),console.error(`[TOKEN ROUTE] Missing required parameters: ${e.join(", ")}`),i.NextResponse.json({error:"Missing required parameters",missing:e},{status:400})}let c=await u(a);console.log(`[TOKEN ROUTE] Got nonce from server-side (${a}):`,c);let d=`${a}/oauth/token`;console.log(`[TOKEN ROUTE] Making token request to: ${d}`);let p=new URLSearchParams({grant_type:"authorization_code",code:o,redirect_uri:"https://flushes.app/auth/callback",client_id:"https://flushes.app/client-metadata.json",code_verifier:t});s&&s!==a&&(console.log("[TOKEN ROUTE] Cross-domain token exchange detected"),console.log("[TOKEN ROUTE] Not adding cross-domain parameters as we're using direct PDS endpoints")),console.log("[TOKEN ROUTE] Complete token request:",{url:d,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",DPoP:r?"[TOKEN PRESENT]":"[MISSING]"},formData:Object.fromEntries(p)});let h=await fetch(d,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",DPoP:r},body:p});console.log(`[TOKEN ROUTE] Response status: ${h.status}`);let T={};h.headers.forEach((e,o)=>{T[o]=e}),console.log("[TOKEN ROUTE] Response headers:",T);let g=await h.json();if(h.ok||(console.error("[TOKEN ROUTE] Token request failed with status:",h.status),console.error("[TOKEN ROUTE] Error response:",g),"invalid_grant"===g.error&&console.error(`[TOKEN ROUTE] Invalid grant error details: 
          - The authorization code might have expired
          - The code_verifier might not match what was used for code_challenge
          - For third-party PDS: resource parameter might be incorrect
          - Client ID might not match what was used in authorization request
          - Redirect URI might not match what was used in authorization request
        `)),"use_dpop_nonce"===g.error){let e=h.headers.get("DPoP-Nonce");return console.log(`[TOKEN ROUTE] Got DPoP-Nonce from error response: ${e}`),i.NextResponse.json({error:"use_dpop_nonce",nonce:e,originalError:g},{status:400})}return h.ok&&(console.log("[TOKEN ROUTE] Token response from Bluesky:",JSON.stringify({...g,access_token:g.access_token?"[REDACTED]":null,refresh_token:g.refresh_token?"[REDACTED]":null})),g.aud?console.log("[TOKEN ROUTE] Token audience:",g.aud):console.warn("[TOKEN ROUTE] No audience in token response")),i.NextResponse.json(g,{status:h.status})}catch(e){return console.error("Token proxy error:",e),i.NextResponse.json({error:"Token proxy error",message:e.message},{status:500})}}async function p(){return new i.NextResponse(null,{status:200,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type, DPoP"}})}let h=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/auth/token/route",pathname:"/api/auth/token",filename:"route",bundlePath:"app/api/auth/token/route"},resolvedPagePath:"/Users/dame/Library/Mobile Documents/com~apple~CloudDocs/Software/flushes/app/src/app/api/auth/token/route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:T,staticGenerationAsyncStorage:g,serverHooks:E}=h,O="/api/auth/token/route";function m(){return(0,a.patchFetch)({serverHooks:E,staticGenerationAsyncStorage:g})}}};var o=require("../../../../webpack-runtime.js");o.C(e);var t=e=>o(o.s=e),r=o.X(0,[276,972],()=>t(81658));module.exports=r})();