@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/README.md +20 -3
- package/dist/{chunk-CbDLau6x.cjs → chunk-C0xms8kb.cjs} +1 -1
- package/dist/client/index.cjs +4 -3
- package/dist/client/index.d.mts +9 -9
- package/dist/client/index.mjs +1 -1
- package/dist/components/client/index.cjs +12 -10
- package/dist/components/client/index.cjs.map +1 -1
- package/dist/components/client/index.d.mts +9 -8
- package/dist/components/client/index.mjs +8 -7
- package/dist/components/client/index.mjs.map +1 -1
- package/dist/components/index.cjs +2 -1
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.mts +5 -5
- package/dist/components/index.mjs.map +1 -1
- package/dist/index.cjs +18 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +16 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{client-xfBYYato.cjs → protect-BCIji2i7.cjs} +10 -10
- package/dist/protect-BCIji2i7.cjs.map +1 -0
- package/dist/{client-D-3RMRNY.mjs → protect-K9srvUkq.mjs} +9 -9
- package/dist/protect-K9srvUkq.mjs.map +1 -0
- package/dist/{types-CsBjAJce.d.mts → types-Cx32VRoI.d.mts} +1 -2
- package/package.json +7 -7
- package/dist/client-D-3RMRNY.mjs.map +0 -1
- package/dist/client-xfBYYato.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
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
|
|
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.
|
|
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
|
|
605
|
+
const customProps = await options.onAccessDenied({ ...context });
|
|
600
606
|
return {
|
|
601
|
-
...customProps
|
|
602
|
-
props: { ...(customProps
|
|
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
|
|
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
|
|
630
|
-
props: { ...customProps
|
|
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]
|
|
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]
|
|
922
|
+
if (isNodeRequest(args[0]) && isNodeResponse(args[1])) {
|
|
917
923
|
({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
|
|
918
924
|
groups = args[2];
|
|
919
925
|
}
|