1import{s as y,j as e,B as g}from"./index-C3IesLzV.js";import{i as N,r as m}from"./vendor-BOYdj2Dv.js";import{M as R}from"./MetaTags-BeiLWqU-.js";const d="2.116.0";class j extends Error{constructor(o){super(o),this.name="OAuthApiUnavailableError"}}function b(){const a=y.auth.oauth;return typeof a?.getAuthorizationDetails=="function"&&typeof a?.approveAuthorization=="function"&&typeof a?.denyAuthorization=="function"}function k(){const a=y.auth.oauth;if(!a||typeof a.getAuthorizationDetails!="function")throw new j("supabase.auth.oauth is not available in this build of @supabase/supabase-js.");return a}function S(a){switch(a){case"missing_authorization_id":return{title:"Missing authorization request",hint:"The URL is missing the authorization_id parameter. Start the connection again from the client application."};case"oauth_api_unavailable":return{title:"OAuth consent API unavailable",hint:"This build of the app can't talk to Supabase's OAuth consent endpoints. If you're a QR Tracker operator, ensure @supabase/supabase-js is at least 2.77.0 and redeploy."};case"authorization_lookup_failed":return{title:"Could not load this authorization request",hint:"Supabase rejected the authorization lookup. Start the connection again from the client application."};case"authorization_expired_or_invalid":return{title:"Authorization request expired",hint:"This consent link is no longer valid. Start the connection again from the client application."};case"decision_failed":return{title:"We couldn't record your decision",hint:"Please try again. If the problem persists, restart the connection from the client application."};case"no_redirect_returned":return{title:"Authorization server didn't return a redirect",hint:"Please restart the connection from the client application."};default:return{title:"Something went wrong",hint:"Please restart the connection from the client application."}}}function C(){const[a]=N(),o=a.get("authorization_id")??"",[_,v]=m.useState(null),[n,s]=m.useState(null),[f,h]=m.useState(!1);m.useEffect(()=>{let l=!0;return(async()=>{if(!o){s({kind:"missing_authorization_id",message:"authorization_id missing from URL"});return}if(console.info("[oauth-consent] supabase-js",d,"auth.oauth?",b()),!b()){s({kind:"oauth_api_unavailable",message:"supabase.auth.oauth API not present on client",detail:`supabase-js ${d}`});return}try{const{data:t}=await y.auth.getSession();if(!t.session){const c=window.location.pathname+window.location.search;window.location.href="/login?redirect="+encodeURIComponent(c);return}const{data:r,error:i}=await k().getAuthorizationDetails(o);if(!l)return;if(i){const c=i.code,p=i.status,A=p===404||p===410||typeof c=="string"&&/expired|invalid|not_found/i.test(c);s({kind:A?"authorization_expired_or_invalid":"authorization_lookup_failed",message:i.message,code:c,status:p}),console.warn("[oauth-consent] getAuthorizationDetails failed",{code:c,status:p});return}const u=r?.redirect_url??r?.redirect_to;if(u&&!r?.client){window.location.href=u;return}v(r)}catch(t){if(!l)return;if(t instanceof j){s({kind:"oauth_api_unavailable",message:t.message,detail:`supabase-js ${d}`});return}s({kind:"unexpected",message:t instanceof Error?t.message:"Failed to load authorization request."})}})(),()=>{l=!1}},[o]);async function w(l){h(!0),s(null);try{const t=k(),{data:r,error:i}=l?await t.approveAuthorization(o):await t.denyAuthorization(o);if(i){h(!1),s({kind:"decision_failed",message:i.message,code:i.code,status:i.status}),console.warn("[oauth-consent] decision failed",{code:i.code,status:i.status});return}const u=r?.redirect_url??r?.redirect_to;if(!u){h(!1),s({kind:"no_redirect_returned",message:"authorization server returned no redirect"});return}window.location.href=u}catch(t){if(h(!1),t instanceof j){s({kind:"oauth_api_unavailable",message:t.message,detail:`supabase-js ${d}`});return}s({kind:"unexpected",message:t instanceof Error?t.message:"Something went wrong."})}}const z=_?.client?.name??"an application",x=n?S(n.kind):null;return e.jsxs("main",{className:"min-h-screen bg-background flex items-center justify-center px-4 py-12",children:[e.jsx(R,{title:"Authorize application · QR Tracker",description:"Approve or deny an application requesting access to your QR Tracker account.",noIndex:!0}),e.jsxs("div",{className:"w-full max-w-md rounded-lg border bg-card p-8 shadow",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Authorize application"}),n&&x?e.jsxs("div",{className:"mt-6 space-y-3",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:x.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x.hint}),e.jsxs("details",{className:"text-xs text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer",children:"Technical details"}),e.jsxs("ul",{className:"mt-2 space-y-0.5",children:[e.jsxs("li",{children:["reason: ",n.kind]}),n.code?e.jsxs("li",{children:["code: ",n.code]}):null,typeof n.status=="number"?e.jsxs("li",{children:["status: ",n.status]}):null,n.detail?e.jsx("li",{children:n.detail}):null,e.jsxs("li",{children:["supabase-js: ",d]}),e.jsxs("li",{children:["auth.oauth present: ",String(b())]})]})]}),e.jsx(g,{variant:"secondary",onClick:()=>window.history.back(),children:"Go back"})]}):_?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-4 text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:z})," is requesting access to your QR Tracker account. If you approve, it will be able to act as you and:"]}),e.jsxs("ul",{className:"mt-3 space-y-1.5 text-sm text-muted-foreground list-disc pl-5",children:[e.jsx("li",{children:"List your tracked QR codes"}),e.jsx("li",{children:"Create new tracked QR codes (counts toward your plan limit)"}),e.jsx("li",{children:"Change where a tracked QR code redirects"}),e.jsx("li",{children:"Read scan analytics for your QR codes"})]}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"It will only ever see your own QR codes. You can revoke this access at any time from your account settings in the connected application."}),e.jsxs("div",{className:"mt-6 flex gap-3",children:[e.jsx(g,{className:"flex-1",disabled:f,onClick:()=>w(!0),children:f?"Workingâ¦":"Approve"}),e.jsx(g,{variant:"secondary",className:"flex-1",disabled:f,onClick:()=>w(!1),children:"Deny"})]})]}):e.jsx("p",{className:"mt-6 text-sm text-muted-foreground",children:"Loadingâ¦"})]})]})}export{C as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.