strapi-custom-auth 1.2.8 → 1.2.10

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
4
+ const react = require("react");
5
5
  const designSystem = require("@strapi/design-system");
6
6
  const DynamicExpenses = ({
7
7
  description,
@@ -14,7 +14,7 @@ const DynamicExpenses = ({
14
14
  value
15
15
  }) => {
16
16
  const tempValue = value ? value.split(":")[0] : null;
17
- const [selection, setSelection] = React.useState(
17
+ const [selection, setSelection] = react.useState(
18
18
  tempValue === "p" ? "percentuali" : tempValue === "f" ? "fisse" : "nessuna"
19
19
  );
20
20
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: "12px" }, children: [
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const React = require("react");
3
- const jsxRuntime = require("react/jsx-runtime");
2
+ const react = require("react");
3
+ require("react/jsx-runtime");
4
4
  const icons = require("@strapi/icons");
5
5
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
6
6
  const v = glob[path];
@@ -20,13 +20,12 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
20
20
  };
21
21
  const PLUGIN_ID = "strapi-custom-auth";
22
22
  const Initializer = ({ setPlugin }) => {
23
- const ref = React.useRef(setPlugin);
24
- React.useEffect(() => {
23
+ const ref = react.useRef(setPlugin);
24
+ react.useEffect(() => {
25
25
  ref.current(PLUGIN_ID);
26
26
  }, []);
27
27
  return null;
28
28
  };
29
- const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.PuzzlePiece, {});
30
29
  const isTokenExpired = (token) => {
31
30
  if (!token) return true;
32
31
  try {
@@ -124,18 +123,6 @@ const fetchInterceptor = (storage) => {
124
123
  };
125
124
  const index = {
126
125
  register(app) {
127
- app.addMenuLink({
128
- to: `plugins/${PluginIcon}`,
129
- icon: PluginIcon,
130
- intlLabel: {
131
- id: `${PLUGIN_ID}.plugin.name`,
132
- defaultMessage: PLUGIN_ID
133
- },
134
- Component: async () => {
135
- const { App } = await Promise.resolve().then(() => require("../_chunks/App-CdSJ6UQk.js"));
136
- return App;
137
- }
138
- });
139
126
  app.registerPlugin({
140
127
  id: PLUGIN_ID,
141
128
  initializer: Initializer,
@@ -155,13 +142,14 @@ const index = {
155
142
  defaultMessage: "Create your Dynamic Expenses"
156
143
  },
157
144
  components: {
158
- Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-ZL8hH1s8.js")).then((module2) => ({
145
+ Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-DS5zRFz3.js")).then((module2) => ({
159
146
  default: module2.DynamicExpenses
160
147
  }))
161
148
  }
162
149
  });
163
150
  const storage = localStorage.getItem("jwtToken") ? localStorage : sessionStorage;
164
151
  if (["microsoft"].includes(storage.getItem("provider"))) {
152
+ console.log("[STRAPI-CUSTOM-AUTH] storage", storage);
165
153
  app.addMenuLink({
166
154
  to: "/custom-logout",
167
155
  icon: icons.SignOut,
@@ -1,6 +1,6 @@
1
1
  import { useRef, useEffect } from "react";
2
- import { jsx } from "react/jsx-runtime";
3
- import { PuzzlePiece, SignOut } from "@strapi/icons";
2
+ import "react/jsx-runtime";
3
+ import { SignOut } from "@strapi/icons";
4
4
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
5
5
  const v = glob[path];
6
6
  if (v) {
@@ -25,7 +25,6 @@ const Initializer = ({ setPlugin }) => {
25
25
  }, []);
26
26
  return null;
27
27
  };
28
- const PluginIcon = () => /* @__PURE__ */ jsx(PuzzlePiece, {});
29
28
  const isTokenExpired = (token) => {
30
29
  if (!token) return true;
31
30
  try {
@@ -123,18 +122,6 @@ const fetchInterceptor = (storage) => {
123
122
  };
124
123
  const index = {
125
124
  register(app) {
126
- app.addMenuLink({
127
- to: `plugins/${PluginIcon}`,
128
- icon: PluginIcon,
129
- intlLabel: {
130
- id: `${PLUGIN_ID}.plugin.name`,
131
- defaultMessage: PLUGIN_ID
132
- },
133
- Component: async () => {
134
- const { App } = await import("../_chunks/App-B-bQ656I.mjs");
135
- return App;
136
- }
137
- });
138
125
  app.registerPlugin({
139
126
  id: PLUGIN_ID,
140
127
  initializer: Initializer,
@@ -161,6 +148,7 @@ const index = {
161
148
  });
162
149
  const storage = localStorage.getItem("jwtToken") ? localStorage : sessionStorage;
163
150
  if (["microsoft"].includes(storage.getItem("provider"))) {
151
+ console.log("[STRAPI-CUSTOM-AUTH] storage", storage);
164
152
  app.addMenuLink({
165
153
  to: "/custom-logout",
166
154
  icon: SignOut,
@@ -3317,18 +3317,25 @@ async function microsoftSignInCallback(ctx) {
3317
3317
  }
3318
3318
  });
3319
3319
  const groupsList = groupResponse?.data.value;
3320
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER groups", groupsList);
3320
3321
  const { mail, givenName, surname } = userResponse?.data;
3321
- const dbUser = await userService.findOneByEmail(mail);
3322
+ const dbUser = await userService.findOneByEmail(mail, { roles: true });
3322
3323
  let activateUser;
3323
3324
  let jwtToken;
3324
3325
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: check user existence");
3325
3326
  if (dbUser) {
3326
3327
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists generating token");
3327
- activateUser = dbUser;
3328
+ const hasRoleMismatch = await roleService.checkMicrosoftUserRolesMismatch(dbUser, groupsList, config2);
3329
+ if (hasRoleMismatch) {
3330
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists but has role mismatch, fixing it.");
3331
+ activateUser = await roleService.updateMicrosoftUserRoles(dbUser, groupsList, config2);
3332
+ } else {
3333
+ activateUser = dbUser;
3334
+ }
3328
3335
  jwtToken = await tokenService.createJwtToken(activateUser);
3329
3336
  } else {
3330
3337
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
3331
- const roles2 = await roleService.retrieveMicrosoftUserRole(groupsList, config2);
3338
+ const roles2 = await roleService.retrieveMicrosoftUserRoles(groupsList, config2);
3332
3339
  const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
3333
3340
  activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
3334
3341
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
@@ -39306,6 +39313,7 @@ var oauth = ({ strapi: strapi2 }) => ({
39306
39313
  renderSignUpSuccess(jwtToken, user, nonce, refreshToken, provider = "custom") {
39307
39314
  const config2 = strapi2.config.get("plugin::strapi-custom-auth");
39308
39315
  const REMEMBER_ME = config2["REMEMBER_ME"];
39316
+ console.log("[STRAPI-CUSTOM-AUTH] Sign up success redirecting to: ", strapi2.config.admin.url);
39309
39317
  let storage = "sessionStorage";
39310
39318
  if (REMEMBER_ME) {
39311
39319
  storage = "localStorage";
@@ -39417,18 +39425,42 @@ var role = ({ strapi: strapi2 }) => ({
39417
39425
  })
39418
39426
  );
39419
39427
  },
39420
- async retrieveMicrosoftUserRole(groupList, config2) {
39428
+ async retrieveMicrosoftUserRoles(groupList, config2) {
39421
39429
  const allowedGroups = /* @__PURE__ */ new Set([
39422
39430
  String(config2["ENTRA_ADMIN_GROUP_NAME"]),
39423
39431
  String(config2["ENTRA_EDITOR_GROUP_NAME"])
39424
39432
  ]);
39425
39433
  const filteredGroups = groupList.filter((group) => allowedGroups.has(group.displayName));
39426
39434
  const dbRoles = await strapi2.db.query("admin::role").findMany();
39435
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles list", dbRoles);
39427
39436
  const roles2 = filteredGroups.map((group) => {
39428
39437
  const roleName = group.displayName.includes("Admin") ? "admin" : "editor";
39429
39438
  return dbRoles.find((role2) => role2.name.toLowerCase().includes(roleName))?.id;
39430
39439
  }).filter(Boolean);
39440
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles matched with entra groups", roles2);
39431
39441
  return roles2;
39442
+ },
39443
+ async checkMicrosoftUserRolesMismatch(user, groupList, config2) {
39444
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: START");
39445
+ const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
39446
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: Roles matched with entra groups ->", entraMatchedRoles);
39447
+ const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
39448
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: User current roles", userCurrentRoles);
39449
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: END");
39450
+ return entraMatchedRoles.some((roleId) => !userCurrentRoles.includes(roleId));
39451
+ },
39452
+ async updateMicrosoftUserRoles(user, groupList, config2) {
39453
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: START");
39454
+ const userService = strapi2.service("admin::user");
39455
+ const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
39456
+ const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
39457
+ const rolesToAdd = entraMatchedRoles.filter((roleId) => !userCurrentRoles.includes(roleId));
39458
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Roles to add ->", rolesToAdd);
39459
+ await userService.updateById(user.id, { roles: [...userCurrentRoles, ...rolesToAdd] });
39460
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Updated user roles");
39461
+ const updatedUser = await userService.findOne(user.id);
39462
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: END");
39463
+ return updatedUser;
39432
39464
  }
39433
39465
  });
39434
39466
  const role$1 = /* @__PURE__ */ getDefaultExportFromCjs(role);
@@ -3302,18 +3302,25 @@ async function microsoftSignInCallback(ctx) {
3302
3302
  }
3303
3303
  });
3304
3304
  const groupsList = groupResponse?.data.value;
3305
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER groups", groupsList);
3305
3306
  const { mail, givenName, surname } = userResponse?.data;
3306
- const dbUser = await userService.findOneByEmail(mail);
3307
+ const dbUser = await userService.findOneByEmail(mail, { roles: true });
3307
3308
  let activateUser;
3308
3309
  let jwtToken;
3309
3310
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: check user existence");
3310
3311
  if (dbUser) {
3311
3312
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists generating token");
3312
- activateUser = dbUser;
3313
+ const hasRoleMismatch = await roleService.checkMicrosoftUserRolesMismatch(dbUser, groupsList, config2);
3314
+ if (hasRoleMismatch) {
3315
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists but has role mismatch, fixing it.");
3316
+ activateUser = await roleService.updateMicrosoftUserRoles(dbUser, groupsList, config2);
3317
+ } else {
3318
+ activateUser = dbUser;
3319
+ }
3313
3320
  jwtToken = await tokenService.createJwtToken(activateUser);
3314
3321
  } else {
3315
3322
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
3316
- const roles2 = await roleService.retrieveMicrosoftUserRole(groupsList, config2);
3323
+ const roles2 = await roleService.retrieveMicrosoftUserRoles(groupsList, config2);
3317
3324
  const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
3318
3325
  activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
3319
3326
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
@@ -39291,6 +39298,7 @@ var oauth = ({ strapi: strapi2 }) => ({
39291
39298
  renderSignUpSuccess(jwtToken, user, nonce, refreshToken, provider = "custom") {
39292
39299
  const config2 = strapi2.config.get("plugin::strapi-custom-auth");
39293
39300
  const REMEMBER_ME = config2["REMEMBER_ME"];
39301
+ console.log("[STRAPI-CUSTOM-AUTH] Sign up success redirecting to: ", strapi2.config.admin.url);
39294
39302
  let storage = "sessionStorage";
39295
39303
  if (REMEMBER_ME) {
39296
39304
  storage = "localStorage";
@@ -39402,18 +39410,42 @@ var role = ({ strapi: strapi2 }) => ({
39402
39410
  })
39403
39411
  );
39404
39412
  },
39405
- async retrieveMicrosoftUserRole(groupList, config2) {
39413
+ async retrieveMicrosoftUserRoles(groupList, config2) {
39406
39414
  const allowedGroups = /* @__PURE__ */ new Set([
39407
39415
  String(config2["ENTRA_ADMIN_GROUP_NAME"]),
39408
39416
  String(config2["ENTRA_EDITOR_GROUP_NAME"])
39409
39417
  ]);
39410
39418
  const filteredGroups = groupList.filter((group) => allowedGroups.has(group.displayName));
39411
39419
  const dbRoles = await strapi2.db.query("admin::role").findMany();
39420
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles list", dbRoles);
39412
39421
  const roles2 = filteredGroups.map((group) => {
39413
39422
  const roleName = group.displayName.includes("Admin") ? "admin" : "editor";
39414
39423
  return dbRoles.find((role2) => role2.name.toLowerCase().includes(roleName))?.id;
39415
39424
  }).filter(Boolean);
39425
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles matched with entra groups", roles2);
39416
39426
  return roles2;
39427
+ },
39428
+ async checkMicrosoftUserRolesMismatch(user, groupList, config2) {
39429
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: START");
39430
+ const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
39431
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: Roles matched with entra groups ->", entraMatchedRoles);
39432
+ const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
39433
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: User current roles", userCurrentRoles);
39434
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: END");
39435
+ return entraMatchedRoles.some((roleId) => !userCurrentRoles.includes(roleId));
39436
+ },
39437
+ async updateMicrosoftUserRoles(user, groupList, config2) {
39438
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: START");
39439
+ const userService = strapi2.service("admin::user");
39440
+ const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
39441
+ const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
39442
+ const rolesToAdd = entraMatchedRoles.filter((roleId) => !userCurrentRoles.includes(roleId));
39443
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Roles to add ->", rolesToAdd);
39444
+ await userService.updateById(user.id, { roles: [...userCurrentRoles, ...rolesToAdd] });
39445
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Updated user roles");
39446
+ const updatedUser = await userService.findOne(user.id);
39447
+ console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: END");
39448
+ return updatedUser;
39417
39449
  }
39418
39450
  });
39419
39451
  const role$1 = /* @__PURE__ */ getDefaultExportFromCjs(role);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.8",
2
+ "version": "1.2.10",
3
3
  "keywords": [],
4
4
  "type": "commonjs",
5
5
  "exports": {