strapi-security-suite
Version:
All-in-one authentication and session security plugin for Strapi v5
163 lines (162 loc) • 8.31 kB
JavaScript
"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");
const index = require("./index-BVsx1rse.js");
const HomePage = () => {
const client = admin.useFetchClient();
const [config, setConfig] = react.useState({
autoLogoutTime: 30,
multipleSessionsControl: false,
passwordExpiryDays: 365,
nonReusablePassword: false,
enablePasswordManagement: false
});
const [success, setSuccess] = react.useState(false);
const [error, setError] = react.useState(null);
react.useEffect(() => {
const fetchConfig = async () => {
try {
const { data } = await client.get(`${index.API_BASE_PATH}/admin/settings`);
if (data?.data) {
setConfig(data.data);
}
} catch {
setError("Failed to load settings. Please refresh the page.");
}
};
fetchConfig();
}, [client]);
const handleChange = (key, value) => {
setConfig((prev) => ({ ...prev, [key]: value }));
};
const saveConfig = async () => {
setError(null);
try {
await client.post(`${index.API_BASE_PATH}/admin/settings`, config);
setSuccess(true);
setTimeout(() => setSuccess(false), index.SUCCESS_ALERT_DURATION);
} catch (err) {
setError(err.response?.data?.error?.message ?? "Failed to save settings.");
}
};
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 10, background: "neutral0", shadow: "filterShadow", borderRadius: "12px", children: [
/* @__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!" }),
error && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { title: "Error", variant: "danger", marginBottom: 4, onClose: () => setError(null), children: error }),
/* @__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-start", 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;
exports.default = App;