@monocloud/auth-nextjs 0.1.5 → 0.1.6

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.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- const require_chunk = require('./chunk-CbDLau6x.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
2
3
  let _monocloud_auth_node_core = require("@monocloud/auth-node-core");
3
4
  let next_server_js = require("next/server.js");
4
5
  let _monocloud_auth_node_core_internal = require("@monocloud/auth-node-core/internal");
5
6
  let _monocloud_auth_node_core_utils = require("@monocloud/auth-node-core/utils");
6
7
  let cookie = require("cookie");
7
- let node_http = require("node:http");
8
8
 
9
9
  //#region src/requests/monocloud-app-router-request.ts
10
10
  var MonoCloudAppRouterRequest = class {
@@ -220,6 +220,12 @@ var MonoCloudCookieRequest = class {
220
220
  const isMonoCloudRequest = (req) => req instanceof MonoCloudAppRouterRequest || req instanceof MonoCloudPageRouterRequest || req instanceof MonoCloudCookieRequest;
221
221
  const isMonoCloudResponse = (res) => res instanceof MonoCloudAppRouterResponse || res instanceof MonoCloudPageRouterResponse || res instanceof MonoCloudCookieResponse;
222
222
  const isAppRouter = (req) => req instanceof Request || req.headers instanceof Headers || typeof req.bodyUsed === "boolean";
223
+ const isNodeRequest = (req) => {
224
+ return !!(req && typeof req === "object" && "headers" in req && !("bodyUsed" in req) && typeof req.on === "function");
225
+ };
226
+ const isNodeResponse = (res) => {
227
+ return !!(res && typeof res === "object" && "setHeader" in res && typeof res.setHeader === "function" && "end" in res && typeof res.end === "function");
228
+ };
223
229
  const getNextRequest = (req) => {
224
230
  if (req instanceof next_server_js.NextRequest) return req;
225
231
  return new next_server_js.NextRequest(req.url, {
@@ -253,7 +259,7 @@ const getMonoCloudCookieReqRes = (req, resOrCtx) => {
253
259
  request = new MonoCloudAppRouterRequest(getNextRequest(req));
254
260
  response = resOrCtx instanceof Response ? new MonoCloudAppRouterResponse(getNextResponse(resOrCtx)) : new MonoCloudCookieResponse();
255
261
  } else {
256
- if (!(req instanceof node_http.IncomingMessage) || !(resOrCtx instanceof node_http.ServerResponse)) throw new _monocloud_auth_node_core.MonoCloudValidationError("Invalid pages router request and response");
262
+ if (!isNodeRequest(req) || !isNodeResponse(resOrCtx)) throw new _monocloud_auth_node_core.MonoCloudValidationError("Invalid pages router request and response");
257
263
  request = new MonoCloudPageRouterRequest(req);
258
264
  response = new MonoCloudPageRouterResponse(resOrCtx);
259
265
  }
@@ -459,7 +465,7 @@ var MonoCloudNextClient = class {
459
465
  constructor(options) {
460
466
  const opt = {
461
467
  ...options ?? {},
462
- userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.5`,
468
+ userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.6`,
463
469
  debugger: (options === null || options === void 0 ? void 0 : options.debugger) ?? "@monocloud:auth-nextjs"
464
470
  };
465
471
  this.registerPublicEnvVariables();
@@ -596,10 +602,10 @@ var MonoCloudNextClient = class {
596
602
  if (!session) {
597
603
  var _options$authParams10, _options$authParams11, _options$authParams12, _options$authParams13, _options$authParams14, _options$authParams15, _options$authParams16, _options$authParams17, _options$authParams18;
598
604
  if (options === null || options === void 0 ? void 0 : options.onAccessDenied) {
599
- const customProps$1 = await options.onAccessDenied({ ...context });
605
+ const customProps = await options.onAccessDenied({ ...context });
600
606
  return {
601
- ...customProps$1 ?? {},
602
- props: { ...(customProps$1 === null || customProps$1 === void 0 ? void 0 : customProps$1.props) ?? {} }
607
+ ...customProps ?? {},
608
+ props: { ...(customProps === null || customProps === void 0 ? void 0 : customProps.props) ?? {} }
603
609
  };
604
610
  }
605
611
  const { routes, appUrl } = this.getOptions();
@@ -621,13 +627,13 @@ var MonoCloudNextClient = class {
621
627
  }
622
628
  if ((options === null || options === void 0 ? void 0 : options.groups) && !(0, _monocloud_auth_node_core_utils.isUserInGroup)(session.user, options.groups, options.groupsClaim ?? process.env.MONOCLOUD_AUTH_GROUPS_CLAIM, options.matchAll)) {
623
629
  var _options$onGroupAcces;
624
- const customProps$1 = await ((_options$onGroupAcces = options.onGroupAccessDenied) === null || _options$onGroupAcces === void 0 ? void 0 : _options$onGroupAcces.call(options, {
630
+ const customProps = await ((_options$onGroupAcces = options.onGroupAccessDenied) === null || _options$onGroupAcces === void 0 ? void 0 : _options$onGroupAcces.call(options, {
625
631
  ...context,
626
632
  user: session.user
627
633
  })) ?? { props: { groupAccessDenied: true } };
628
634
  return {
629
- ...customProps$1,
630
- props: { ...customProps$1.props ?? {} }
635
+ ...customProps,
636
+ props: { ...customProps.props ?? {} }
631
637
  };
632
638
  }
633
639
  const customProps = (options === null || options === void 0 ? void 0 : options.getServerSideProps) ? await options.getServerSideProps(context) : {};
@@ -800,7 +806,7 @@ var MonoCloudNextClient = class {
800
806
  ({request, response} = getMonoCloudCookieReqRes(args[0], void 0));
801
807
  options = args[1];
802
808
  }
803
- else if (args.length === 2 && args[0] instanceof node_http.IncomingMessage && args[1] instanceof node_http.ServerResponse) ({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
809
+ else if (args.length === 2 && isNodeRequest(args[0]) && isNodeResponse(args[1])) ({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
804
810
  else {
805
811
  ({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
806
812
  options = args[2];
@@ -913,7 +919,7 @@ var MonoCloudNextClient = class {
913
919
  groups = args[1];
914
920
  options = args[2];
915
921
  }
916
- if (args[0] instanceof node_http.IncomingMessage && args[1] instanceof node_http.ServerResponse) {
922
+ if (isNodeRequest(args[0]) && isNodeResponse(args[1])) {
917
923
  ({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
918
924
  groups = args[2];
919
925
  }