1import{j as t}from"./ui-vendor-CYOVLxNwXU.js";import{a as b,u as v,g as k,E as N,j as S,L as w,k as T,A as E}from"./index-CUBBvIcp0x.js";import{u as I,f as A,a as c}from"./react-vendor-cgUCpBnF-D.js";import"./charts-vendor-D43QTVcFaE.js";import"./radix-vendor-DXvFAmVrUY.js";import"./flow-vendor-BrciDm0dtA.js";const m=new Map;function L(e){const s=m.get(e);if(s)return s;const l=T(`${E}/api/impersonate`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:e})}).then(async n=>({ok:n.ok,...await n.json()})).finally(()=>m.delete(e));return m.set(e,l),l}const h=()=>{const e=sessionStorage.getItem("impersonation_token"),s=sessionStorage.getItem("impersonation_user");return e&&s?{token:e,user:s}:null};function D(){const{t:e}=b(),s=I(),[l]=A(),{refreshUser:n}=v(),[p,f]=c.useState(null),[y,j]=c.useState(0),d=l.get("token"),x=c.useCallback(async()=>{await n(),s("/dashboard",{replace:!0})},[n,s]),g=c.useRef({enter:x,t:e});return g.current={enter:x,t:e},c.useEffect(()=>{let o=!1;const u=a=>{o||f(a)};return(async()=>{const{enter:a,t:i}=g.current;if(!d)return h()?a():u(i.impersonate.noTokenProvided);try{const r=await L(d);if(o)return;if(!r.ok)return r.error?.includes("already been used")&&h()?a():u(r.error||i.impersonate.failedToValidateToken);if(!r.session||!r.user)return u(i.impersonate.failedToValidateToken);sessionStorage.setItem("impersonation_token",r.session.token),sessionStorage.setItem("impersonation_user",JSON.stringify(r.user)),sessionStorage.setItem("impersonation_by",JSON.stringify(r.impersonator??{role:"admin"})),await a()}catch(r){console.warn(k(N.AUTH_IMPERSONATION_FAILED),r),u(S(r)?i.pages.connectionFailedDetail:i.impersonate.unexpectedError)}})(),()=>{o=!0}},[d,y]),p?t.jsx("div",{className:"flex min-h-dvh items-center justify-center bg-background p-4",children:t.jsxs("div",{className:"w-full max-w-md rounded-lg border bg-card p-8 text-center shadow-xl",children:[t.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-destructive/15",children:t.jsx("svg",{className:"h-8 w-8 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),t.jsx("h2",{className:"mt-6 font-bold text-2xl text-destructive",children:e.impersonate.errorTitle}),t.jsx("p",{className:"mt-2 text-muted-foreground",children:p}),t.jsxs("div",{className:"mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-center",children:[t.jsx("button",{type:"button",onClick:()=>s("/dashboard"),className:"min-h-11 rounded-lg bg-secondary px-6 py-2 text-secondary-foreground transition-colors hover:bg-secondary/80",children:e.impersonate.returnToDashboard}),d&&t.jsx("button",{type:"button",onClick:()=>{f(null),j(o=>o+1)},className:"min-h-11 rounded-lg bg-primary px-6 py-2 text-primary-foreground transition-colors hover:bg-primary/90",children:e.common.retry})]})]})}):t.jsx("div",{className:"flex min-h-dvh items-center justify-center bg-background p-4",children:t.jsxs("div",{className:"flex flex-col items-center gap-6",children:[t.jsx(w,{size:200,animateLines:!0,animateStar:!1}),t.jsx("p",{className:"text-muted-foreground text-sm",children:e.impersonate.verifyingAccess})]})})}export{D as Impersonate};
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.