UNPKG

strapi-security-suite

Version:

All-in-one authentication and session security plugin for Strapi v5

192 lines (191 loc) 8.8 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const admin = require("@strapi/strapi/admin"); const reactRouterDom = require("react-router-dom"); const react = require("react"); const designSystem = require("@strapi/design-system"); function IsLoggedInDebugger() { const [value, setValue] = react.useState(localStorage.getItem("isLoggedIn")); react.useEffect(() => { const originalSetItem = Storage.prototype.setItem; Storage.prototype.setItem = function(key, val) { if (key === "isLoggedIn") { console.log(`🕵️ isLoggedIn changed to:`, val); setValue(val); } return originalSetItem.apply(this, arguments); }; const interval = setInterval(() => { const current = localStorage.getItem("isLoggedIn"); setValue(current); }, 1e3); return () => { clearInterval(interval); Storage.prototype.setItem = originalSetItem; }; }, []); return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "fixed", bottom: "10px", right: "10px", backgroundColor: "rgba(0,0,0,0.7)", color: "lime", padding: "10px", borderRadius: "10px", fontSize: "14px", zIndex: 9999, fontFamily: "monospace" }, children: [ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: 'localStorage["isLoggedIn"]:' }), " ", String(value) ] }); } const HomePage = () => { const [config, setConfig] = react.useState({ autoLogoutTime: 30, multipleSessionsControl: false, passwordExpiryDays: 365, nonReusablePassword: false, enablePasswordManagement: false }); const [success, setSuccess] = react.useState(false); react.useEffect(() => { const fetchConfig = async () => { try { const res = await fetch("/strapi-security-suite/admin/settings"); const json = await res.json(); setConfig(json); } catch (e) { console.error("❌ Failed to fetch config", e); } }; fetchConfig(); }, []); const handleChange = (key, value) => { setConfig((prev) => ({ ...prev, [key]: value })); }; const saveConfig = async () => { try { const res = await fetch("/strapi-security-suite/admin/settings", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(config) }); if (res.ok) { setSuccess(true); setTimeout(() => setSuccess(false), 3e3); } } catch (err) { console.error("❌ Save failed:", err); } }; return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 10, background: "neutral0", shadow: "filterShadow", borderRadius: "12px", children: [ /* @__PURE__ */ jsxRuntime.jsx(IsLoggedInDebugger, {}), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", as: "h1", fontWeight: "bold", children: "Security & Session Settings" }), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", paddingTop: 2, paddingBottom: 4, children: "Configure session duration, password policies, and security settings." }), success && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { title: "Success", variant: "success", marginBottom: 4, children: "Configuration saved successfully!" }), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", justifyContent: "space-between", gap: 6, paddingTop: 6, wrap: "wrap", children: [ /* @__PURE__ */ jsxRuntime.jsxs( designSystem.Box, { flex: "1", minWidth: "400px", padding: 6, background: "neutral100", borderRadius: "8px", shadow: "tableShadow", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", children: "Session Management" }), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, { marginTop: 2, marginBottom: 4 }), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-star", gap: 4, children: [ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "row", gap: 4, children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "Auto Logout Time (minutes)" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.NumberInput, { minValue: 1, value: config.autoLogoutTime, onValueChange: (value) => handleChange("autoLogoutTime", value) } ) ] }), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "Activate multiple sessions control?" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.Switch, { checked: config.multipleSessionsControl, onCheckedChange: () => handleChange("multipleSessionsControl", !config.multipleSessionsControl) } ) ] }) ] }) ] } ), /* @__PURE__ */ jsxRuntime.jsxs( designSystem.Box, { flex: "1", minWidth: "400px", minHeight: "173px", padding: 6, background: "neutral100", borderRadius: "8px", shadow: "tableShadow", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", children: "Password Management" }), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, { marginTop: 2, marginBottom: 4 }), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 4, children: [ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "Activate Password Control?" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.Switch, { checked: config.enablePasswordManagement, onCheckedChange: () => handleChange("enablePasswordManagement", !config.enablePasswordManagement) } ) ] }), config.enablePasswordManagement && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 5, children: [ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 3, children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "Password Expiry (days)?" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.NumberInput, { minValue: 1, value: config.passwordExpiryDays, onValueChange: (value) => handleChange("passwordExpiryDays", value) } ) ] }), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 3, children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "Activate Non-Reusable Password?" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.Switch, { checked: config.nonReusablePassword, onCheckedChange: () => handleChange("nonReusablePassword", !config.nonReusablePassword) } ) ] }) ] }) ] }) ] } ) ] }), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", paddingTop: 6, paddingBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: saveConfig, variant: "secondary", size: "L", shadow: "buttonShadow", children: "Save Settings" }) }) ] }); }; const App = () => { return /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { index: true, element: /* @__PURE__ */ jsxRuntime.jsx(HomePage, {}) }), /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "*", element: /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {}) }) ] }); }; exports.App = App;