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