1import{j as e,_ as m,B as d,a4 as T,ag as I,m as E,e as F,o as L,r as i,a9 as P,al as N,aa as B,ab as O,ac as R}from"./index-OkXy-d5Y.js";import{A as w,a as v}from"./alert-0QuNooNy.js";import{C as S,b as y}from"./card-BOYNs0rn.js";import{L as C}from"./loader-circle-Cq8KN2OP.js";function D({status:t,provider:r,error:s,onBackToLogin:a,onRetry:o}){return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30 px-4",children:e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(S,{className:"overflow-hidden",children:e.jsxs(y,{className:"flex flex-col items-center gap-3 pt-2 pb-10 px-8",children:[t==="loading"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-14 w-14 text-primary animate-spin my-8"}),e.jsx("h2",{className:"text-2xl font-bold text-center",children:"Hold on â Smonku is opening the doorâ¦"}),e.jsx("p",{className:"text-base text-muted-foreground text-center",children:"Just a moment while Smonku checks everything"})]}),t==="success"&&e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"monk_happy_logged_in",alt:"Smonku",width:512,height:640,className:"w-60 h-60 object-cover smonku-fade smonku-enter"}),e.jsx("h2",{className:"text-2xl font-bold text-center smonku-text-1",children:"Welcome home!"}),e.jsx("p",{className:"text-base text-muted-foreground text-center smonku-text-2",children:"Smonku remembered you. Taking you to your dashboardâ¦"})]}),t==="error"&&e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"monk_sad_login_failed",alt:"Smonku",width:512,height:410,className:"w-60 h-60 object-cover smonku-fade smonku-enter"}),e.jsx("h2",{className:"text-2xl font-bold text-center smonku-text-1",children:"The door didn't open this time"}),e.jsx("p",{className:"text-base text-muted-foreground text-center smonku-text-2",children:"Smonku tried, but something went wrong. Try again?"}),e.jsx(w,{variant:"destructive",className:"w-full mt-2 smonku-text-2",children:e.jsx(v,{children:s})}),e.jsxs("div",{className:"flex gap-3 w-full mt-2 smonku-text-2",children:[e.jsx(d,{variant:"outline",className:"flex-1",onClick:a,children:"Back to Sign In"}),e.jsx(d,{className:"flex-1",onClick:o,children:"Try Again"})]})]})]})})})})}function H({status:t,provider:r,error:s,onBackToLogin:a,onRetry:o}){return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30 px-4",children:e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(S,{className:"overflow-hidden",children:e.jsxs(y,{className:"flex flex-col items-center gap-3 pt-2 pb-10 px-8",children:[t==="loading"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-14 w-14 text-primary animate-spin my-8"}),e.jsx("h2",{className:"text-2xl font-bold text-center",children:"Hold on â Smonku is opening the doorâ¦"}),e.jsx("p",{className:"text-base text-muted-foreground text-center",children:"Just a moment while Smonku checks everything"})]}),t==="success"&&e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"monk_happy_logged_in",alt:"Smonku",width:512,height:640,className:"w-60 h-60 object-cover smonku-fade smonku-enter"}),e.jsx("h2",{className:"text-2xl font-bold text-center smonku-text-1",children:"Welcome home!"}),e.jsx("p",{className:"text-base text-muted-foreground text-center smonku-text-2",children:"Smonku remembered you. Head back to the terminal."})]}),t==="error"&&e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"monk_sad_login_failed",alt:"Smonku",width:512,height:410,className:"w-60 h-60 object-cover smonku-fade smonku-enter"}),e.jsx("h2",{className:"text-2xl font-bold text-center smonku-text-1",children:"The door didn't open this time"}),e.jsx("p",{className:"text-base text-muted-foreground text-center smonku-text-2",children:"Smonku tried, but something went wrong. Try again?"}),e.jsx(w,{variant:"destructive",className:"w-full mt-2 smonku-text-2",children:e.jsx(v,{children:s})}),e.jsxs("div",{className:"flex gap-3 w-full mt-2 smonku-text-2",children:[e.jsx(d,{variant:"outline",className:"flex-1",onClick:a,children:"Back to Sign In"}),e.jsx(d,{className:"flex-1",onClick:o,children:"Try Again"})]})]})]})})})})}function K(){const{provider:t}=T(),[r]=I(),s=E(),a=F(),o=L(R),[u,n]=i.useState("loading"),[_,c]=i.useState(""),A=i.useRef(!!sessionStorage.getItem("smritea_cli_authorize_context"));i.useEffect(()=>()=>{a(P())},[a]),i.useEffect(()=>{const f=r.get("code")??"",k=r.get("state")??"",j=r.get("error");
1if(j){c(`OAuth error: ${j}`),n("error");return}if(!f||!t){c("Missing OAuth callback parameters."),n("error");return}const p=`oauth_state_${t}`,b=sessionStorage.getItem(p);if(!b){c("Session expired. Please try again."),n("error");return}if(b!==k){c("CSRF token mismatch. Please try again."),n("error");return}sessionStorage.removeItem(p),(async()=>{const x=await a(N({provider:t,code:f,state:k}));if(N.fulfilled.match(x)){if(B(x.payload,l=>s(l,{replace:!0})))return;n("success"),setTimeout(()=>O(s,{replace:!0}),1500)}else{const l=x.payload;c((l==null?void 0:l.message)??"OAuth authentication failed"),n("error")}})()},[t,r,s,a]);const h=_||o||"",g={onBackToLogin:()=>s("/auth/login"),onRetry:()=>window.history.back()};return A.current?e.jsx(H,{status:u,provider:t,error:h,...g}):e.jsx(D,{status:u,provider:t,error:h,...g})}export{K as OAuthCallbackPage};
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.