@kinde-oss/kinde-auth-react
Version:
Kinde React SDK for authentication
1 lines • 1.62 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useKindeAuth-BqgGb6if.cjs"),t=require("./js-utils-LjN61ZXr.cjs");let n=require("react");n=e.r(n,1);let r=require("react/jsx-runtime");function i({children:e}){return(0,r.jsxs)(`div`,{style:{padding:`20px`,textAlign:`center`,color:`#666`,fontFamily:`system-ui, -apple-system, sans-serif`},children:[(0,r.jsx)(`h3`,{children:`Protected Route`}),(0,r.jsx)(`p`,{children:`This component requires react-router-dom to be installed.`}),(0,r.jsxs)(`p`,{children:[`Please install it: `,(0,r.jsx)(`code`,{children:`npm install react-router-dom`})]}),(0,r.jsx)(`div`,{style:{marginTop:`20px`,padding:`10px`,border:`1px solid #ddd`,borderRadius:`4px`},children:e})]})}function a({children:a,has:o,fallbackPath:s=`/`}){let{isLoading:c,isAuthenticated:l}=e.t(),[u,d]=(0,n.useState)(!1),[f,p]=(0,n.useState)(null),[m,h]=(0,n.useState)(null),[g,_]=(0,n.useState)(null);return(0,n.useEffect)(()=>{(async()=>{try{let{Navigate:e}=await import(`react-router-dom`);h(()=>e),_(!0)}catch{console.warn(`react-router-dom is not available. ProtectedRoute will render a fallback.`),_(!1)}})()},[]),(0,n.useEffect)(()=>{l&&(async()=>{if(!o){p(!0);return}d(!0);try{let e=await t.s(o);p(e)}catch(e){console.error(`Access check failed:`,e),p(!1)}finally{d(!1)}})()},[o,l]),g===null||c||u?(0,r.jsx)(`div`,{children:`Loading...`}):g===!1?(0,r.jsx)(i,{children:a}):!l||f===!1?m?(0,r.jsx)(m,{to:s,replace:!0}):(0,r.jsx)(`div`,{children:`Redirecting...`}):f===null?(0,r.jsx)(`div`,{children:`Loading...`}):(0,r.jsx)(r.Fragment,{children:a})}exports.ProtectedRoute=a;