strapi-identity 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import { useState, useEffect } from "react";
3
3
  import { W as WarningAlert } from "./WarningAlert-VU011LVF.mjs";
4
4
  import { Box, Flex, Typography, Grid, Button } from "@strapi/design-system";
5
- import { g as getToken, a as getTranslation } from "./index-CuphCaxI.mjs";
5
+ import { g as getToken, a as getTranslation } from "./index-BGCzWKE5.mjs";
6
6
  import { useIntl } from "react-intl";
7
7
  const AdminReset = ({ id }) => {
8
8
  const { formatMessage } = useIntl();
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const WarningAlert = require("./WarningAlert-DFE5euMk.js");
6
6
  const designSystem = require("@strapi/design-system");
7
- const index = require("./index-BM19x6ag.js");
7
+ const index = require("./index-Z7ZoOcpL.js");
8
8
  const reactIntl = require("react-intl");
9
9
  const AdminReset = ({ id }) => {
10
10
  const { formatMessage } = reactIntl.useIntl();
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const designSystem = require("@strapi/design-system");
6
- const index = require("./index-BM19x6ag.js");
6
+ const index = require("./index-Z7ZoOcpL.js");
7
7
  const reactIntl = require("react-intl");
8
8
  function RemoveModal({ open, onOpenChange, onSubmit }) {
9
9
  const { formatMessage } = reactIntl.useIntl();
@@ -200,14 +200,10 @@ const ProfileToggle = () => {
200
200
  const statusBody = await statusRes.json();
201
201
  const enabledBody = await enabledRes.json();
202
202
  if (!statusRes.ok) {
203
- throw new Error(
204
- `${statusRes.status} - ${statusBody.error || "Failed to get MFA status"}`
205
- );
203
+ throw new Error(`${statusRes.status} - ${statusBody.error || "Failed to get MFA status"}`);
206
204
  }
207
205
  if (!enabledRes.ok) {
208
- throw new Error(
209
- `${enabledRes.status} - ${enabledBody.error || "Failed to get MFA config"}`
210
- );
206
+ throw new Error(`${enabledRes.status} - ${enabledBody.error || "Failed to get MFA config"}`);
211
207
  }
212
208
  setMfaEnabled(enabledBody.data);
213
209
  setEnabled(statusBody.data?.status || null);
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useState, useEffect } from "react";
3
3
  import { Modal, Flex, Typography, TextInput, Button, Box, Grid, Field, Toggle } from "@strapi/design-system";
4
- import { a as getTranslation, I as InputOTP, b as InputOTPGroup, c as InputOTPSlot, d as InputOTPSeparator, g as getToken, C as ConfirmModal, E as EmailOTPModal } from "./index-CuphCaxI.mjs";
4
+ import { a as getTranslation, I as InputOTP, b as InputOTPGroup, c as InputOTPSlot, d as InputOTPSeparator, g as getToken, C as ConfirmModal, E as EmailOTPModal } from "./index-BGCzWKE5.mjs";
5
5
  import { useIntl } from "react-intl";
6
6
  function RemoveModal({ open, onOpenChange, onSubmit }) {
7
7
  const { formatMessage } = useIntl();
@@ -198,14 +198,10 @@ const ProfileToggle = () => {
198
198
  const statusBody = await statusRes.json();
199
199
  const enabledBody = await enabledRes.json();
200
200
  if (!statusRes.ok) {
201
- throw new Error(
202
- `${statusRes.status} - ${statusBody.error || "Failed to get MFA status"}`
203
- );
201
+ throw new Error(`${statusRes.status} - ${statusBody.error || "Failed to get MFA status"}`);
204
202
  }
205
203
  if (!enabledRes.ok) {
206
- throw new Error(
207
- `${enabledRes.status} - ${enabledBody.error || "Failed to get MFA config"}`
208
- );
204
+ throw new Error(`${enabledRes.status} - ${enabledBody.error || "Failed to get MFA config"}`);
209
205
  }
210
206
  setMfaEnabled(enabledBody.data);
211
207
  setEnabled(statusBody.data?.status || null);
@@ -6,7 +6,7 @@ const WarningAlert = require("./WarningAlert-DFE5euMk.js");
6
6
  const admin = require("@strapi/strapi/admin");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
- const index = require("./index-BM19x6ag.js");
9
+ const index = require("./index-Z7ZoOcpL.js");
10
10
  const reactIntl = require("react-intl");
11
11
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
12
12
  var lodash$1 = { exports: {} };
@@ -4,7 +4,7 @@ import { W as WarningAlert } from "./WarningAlert-VU011LVF.mjs";
4
4
  import { useNotification, Page, Layouts } from "@strapi/strapi/admin";
5
5
  import { Button, Flex, Typography, Grid, Field, Toggle, TextInput, Textarea } from "@strapi/design-system";
6
6
  import { Check } from "@strapi/icons";
7
- import { g as getToken, a as getTranslation } from "./index-CuphCaxI.mjs";
7
+ import { g as getToken, a as getTranslation } from "./index-BGCzWKE5.mjs";
8
8
  import { useIntl } from "react-intl";
9
9
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
10
10
  var lodash$1 = { exports: {} };
@@ -1953,24 +1953,23 @@ const plugin = {
1953
1953
  },
1954
1954
  id: "strapi-identity-settings",
1955
1955
  to: `/${PLUGIN_ID}`,
1956
- Component: () => import("./SettingsPage-52kVQn7c.mjs"),
1956
+ Component: () => import("./SettingsPage-DhdlOuM4.mjs"),
1957
1957
  permissions: [{ action: "plugin::strapi-identity.settings.update" }]
1958
1958
  });
1959
1959
  app.addMiddlewares([mfaRedirect]);
1960
1960
  const injections = initialiseInjections(app);
1961
- console.log(app);
1962
1961
  injections.registerRoute({
1963
1962
  id: "profile-toggle",
1964
1963
  route: "/admin/me",
1965
1964
  selector: '#main-content form[method="put"] > :nth-child(2) > div > div > div:nth-child(2)',
1966
- Component: () => import("./ProfileToggle-Z87n9Js6.mjs")
1965
+ Component: () => import("./ProfileToggle-U8uYHOxp.mjs")
1967
1966
  });
1968
1967
  injections.registerRoute({
1969
1968
  id: "admin-reset",
1970
1969
  route: "/admin/settings/users/:id",
1971
1970
  selector: '#main-content form[method="put"] > :nth-child(2) > div > div:nth-child(2)',
1972
1971
  permissions: [{ action: "plugin::strapi-identity.settings.update" }],
1973
- Component: () => import("./AdminReset-8bbnTK5T.mjs")
1972
+ Component: () => import("./AdminReset-C8tJMMQS.mjs")
1974
1973
  });
1975
1974
  InjectVerify(app);
1976
1975
  InjectEnforced(app);
@@ -1973,24 +1973,23 @@ const plugin = {
1973
1973
  },
1974
1974
  id: "strapi-identity-settings",
1975
1975
  to: `/${PLUGIN_ID}`,
1976
- Component: () => Promise.resolve().then(() => require("./SettingsPage-GcVWCKZU.js")),
1976
+ Component: () => Promise.resolve().then(() => require("./SettingsPage-CZJeoZM-.js")),
1977
1977
  permissions: [{ action: "plugin::strapi-identity.settings.update" }]
1978
1978
  });
1979
1979
  app.addMiddlewares([mfaRedirect]);
1980
1980
  const injections = strapiAdminPortal.initialiseInjections(app);
1981
- console.log(app);
1982
1981
  injections.registerRoute({
1983
1982
  id: "profile-toggle",
1984
1983
  route: "/admin/me",
1985
1984
  selector: '#main-content form[method="put"] > :nth-child(2) > div > div > div:nth-child(2)',
1986
- Component: () => Promise.resolve().then(() => require("./ProfileToggle-DklJn1dC.js"))
1985
+ Component: () => Promise.resolve().then(() => require("./ProfileToggle-DAWXMfz9.js"))
1987
1986
  });
1988
1987
  injections.registerRoute({
1989
1988
  id: "admin-reset",
1990
1989
  route: "/admin/settings/users/:id",
1991
1990
  selector: '#main-content form[method="put"] > :nth-child(2) > div > div:nth-child(2)',
1992
1991
  permissions: [{ action: "plugin::strapi-identity.settings.update" }],
1993
- Component: () => Promise.resolve().then(() => require("./AdminReset-BTaE7Xxb.js"))
1992
+ Component: () => Promise.resolve().then(() => require("./AdminReset-CB9VgfLp.js"))
1994
1993
  });
1995
1994
  InjectVerify(app);
1996
1995
  InjectEnforced(app);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const index = require("./index-BM19x6ag.js");
3
+ const index = require("./index-Z7ZoOcpL.js");
4
4
  require("strapi-admin-portal");
5
5
  exports.default = index.plugin;
@@ -1,4 +1,4 @@
1
- import { p } from "./index-CuphCaxI.mjs";
1
+ import { p } from "./index-BGCzWKE5.mjs";
2
2
  import "strapi-admin-portal";
3
3
  export {
4
4
  p as default
@@ -4030,12 +4030,20 @@ const replaceLogin = (route2, secret2, domain) => {
4030
4030
  };
4031
4031
  const registerMiddlewares = (server) => {
4032
4032
  const configService = strapi.service("plugin::strapi-identity.config");
4033
+ const tokenName = strapi.config.get("admin.auth.cookie.name") || "jwtToken";
4033
4034
  server.use(async (ctx, next) => {
4034
4035
  const mfaCookie = ctx.cookies.get("strapi_admin_mfa");
4035
- if (mfaCookie && ctx.path.startsWith("/admin/auth")) {
4036
- ctx.cookies.set("jwtToken", null, { expires: /* @__PURE__ */ new Date(0) });
4037
- ctx.redirect("/admin/strapi-identity/verify");
4038
- return;
4036
+ if (mfaCookie) {
4037
+ if (ctx.path.startsWith("/admin/auth")) {
4038
+ ctx.cookies.set(tokenName, null, { expires: /* @__PURE__ */ new Date(0) });
4039
+ ctx.redirect("/admin/strapi-identity/verify");
4040
+ return;
4041
+ }
4042
+ if (["/admin/ai-token", "/admin/ai-usage", "/admin/ai-feature-config"].includes(ctx.path)) {
4043
+ ctx.status = 404;
4044
+ ctx.body = { data: null, error: { status: 404, message: "Not Found" } };
4045
+ return;
4046
+ }
4039
4047
  }
4040
4048
  if (!mfaCookie && ctx.path === "/admin/strapi-identity/verify") {
4041
4049
  ctx.redirect("/admin");
@@ -4044,7 +4052,7 @@ const registerMiddlewares = (server) => {
4044
4052
  await next();
4045
4053
  });
4046
4054
  server.use(async (ctx, next) => {
4047
- const cookie = ctx.cookies.get("jwtToken");
4055
+ const cookie = ctx.cookies.get(tokenName);
4048
4056
  if (!cookie) {
4049
4057
  await next();
4050
4058
  return;
@@ -4881,13 +4889,13 @@ const disableMFAForAllUsers = async () => {
4881
4889
  strapi.log.error("Error disabling MFA for all users");
4882
4890
  }
4883
4891
  };
4884
- const checkUserByJWT = async (jwtToken) => {
4892
+ const checkUserByJWT = async (token) => {
4885
4893
  const config2 = await getConfig();
4886
4894
  const secret2 = strapi.config.get("admin.auth.secret");
4887
4895
  if (!config2.enabled) return false;
4888
4896
  let userId;
4889
4897
  try {
4890
- const decoded = jwt.verify(jwtToken, secret2);
4898
+ const decoded = jwt.verify(token, secret2);
4891
4899
  userId = decoded.userId || decoded.id;
4892
4900
  } catch {
4893
4901
  return false;
@@ -4023,12 +4023,20 @@ const replaceLogin = (route2, secret2, domain) => {
4023
4023
  };
4024
4024
  const registerMiddlewares = (server) => {
4025
4025
  const configService = strapi.service("plugin::strapi-identity.config");
4026
+ const tokenName = strapi.config.get("admin.auth.cookie.name") || "jwtToken";
4026
4027
  server.use(async (ctx, next) => {
4027
4028
  const mfaCookie = ctx.cookies.get("strapi_admin_mfa");
4028
- if (mfaCookie && ctx.path.startsWith("/admin/auth")) {
4029
- ctx.cookies.set("jwtToken", null, { expires: /* @__PURE__ */ new Date(0) });
4030
- ctx.redirect("/admin/strapi-identity/verify");
4031
- return;
4029
+ if (mfaCookie) {
4030
+ if (ctx.path.startsWith("/admin/auth")) {
4031
+ ctx.cookies.set(tokenName, null, { expires: /* @__PURE__ */ new Date(0) });
4032
+ ctx.redirect("/admin/strapi-identity/verify");
4033
+ return;
4034
+ }
4035
+ if (["/admin/ai-token", "/admin/ai-usage", "/admin/ai-feature-config"].includes(ctx.path)) {
4036
+ ctx.status = 404;
4037
+ ctx.body = { data: null, error: { status: 404, message: "Not Found" } };
4038
+ return;
4039
+ }
4032
4040
  }
4033
4041
  if (!mfaCookie && ctx.path === "/admin/strapi-identity/verify") {
4034
4042
  ctx.redirect("/admin");
@@ -4037,7 +4045,7 @@ const registerMiddlewares = (server) => {
4037
4045
  await next();
4038
4046
  });
4039
4047
  server.use(async (ctx, next) => {
4040
- const cookie = ctx.cookies.get("jwtToken");
4048
+ const cookie = ctx.cookies.get(tokenName);
4041
4049
  if (!cookie) {
4042
4050
  await next();
4043
4051
  return;
@@ -4874,13 +4882,13 @@ const disableMFAForAllUsers = async () => {
4874
4882
  strapi.log.error("Error disabling MFA for all users");
4875
4883
  }
4876
4884
  };
4877
- const checkUserByJWT = async (jwtToken) => {
4885
+ const checkUserByJWT = async (token) => {
4878
4886
  const config2 = await getConfig();
4879
4887
  const secret2 = strapi.config.get("admin.auth.secret");
4880
4888
  if (!config2.enabled) return false;
4881
4889
  let userId;
4882
4890
  try {
4883
- const decoded = jwt.verify(jwtToken, secret2);
4891
+ const decoded = jwt.verify(token, secret2);
4884
4892
  userId = decoded.userId || decoded.id;
4885
4893
  } catch {
4886
4894
  return false;
@@ -50,8 +50,8 @@ export declare const updateConfig: (data: Partial<typeof defaultConfig>) => Prom
50
50
  }>;
51
51
  /**
52
52
  * Checks if a user has MFA enabled by verifying the provided JWT token and checking for an associated MFA token in the database
53
- * @param jwtToken the JWT token to verify and extract the user ID from
53
+ * @param token the JWT token to verify and extract the user ID from
54
54
  * @returns true if the user has MFA enabled, false otherwise
55
55
  */
56
- export declare const checkUserByJWT: (jwtToken: string) => Promise<boolean>;
56
+ export declare const checkUserByJWT: (token: string) => Promise<boolean>;
57
57
  export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.0",
2
+ "version": "0.7.1",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",