@monocloud/auth-nextjs 0.1.3 → 0.1.5
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/client/index.cjs +1 -1
- package/dist/client/index.d.mts +43 -5
- package/dist/client/index.mjs +1 -1
- package/dist/{client-CnvBgZM-.mjs → client-D-3RMRNY.mjs} +43 -9
- package/dist/client-D-3RMRNY.mjs.map +1 -0
- package/dist/{client-Be6A2vEn.cjs → client-xfBYYato.cjs} +43 -9
- package/dist/client-xfBYYato.cjs.map +1 -0
- package/dist/components/client/index.cjs +9 -9
- package/dist/components/client/index.cjs.map +1 -1
- package/dist/components/client/index.d.mts +13 -8
- package/dist/components/client/index.mjs +9 -9
- package/dist/components/client/index.mjs.map +1 -1
- package/dist/components/index.d.mts +1 -1
- package/dist/index.cjs +29 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +21 -12
- package/dist/index.mjs +30 -14
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DOfZTKa6.d.mts → types-CsBjAJce.d.mts} +79 -20
- package/package.json +3 -3
- package/dist/client-Be6A2vEn.cjs.map +0 -1
- package/dist/client-CnvBgZM-.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -222,11 +222,28 @@ const isMonoCloudResponse = (res) => res instanceof MonoCloudAppRouterResponse |
|
|
|
222
222
|
const isAppRouter = (req) => req instanceof Request || req.headers instanceof Headers || typeof req.bodyUsed === "boolean";
|
|
223
223
|
const getNextRequest = (req) => {
|
|
224
224
|
if (req instanceof next_server_js.NextRequest) return req;
|
|
225
|
-
return new next_server_js.NextRequest(req
|
|
225
|
+
return new next_server_js.NextRequest(req.url, {
|
|
226
|
+
method: req.method,
|
|
227
|
+
headers: req.headers,
|
|
228
|
+
body: req.body,
|
|
229
|
+
duplex: req.duplex ?? "half"
|
|
230
|
+
});
|
|
226
231
|
};
|
|
227
232
|
const getNextResponse = (res) => {
|
|
228
233
|
if (res instanceof next_server_js.NextResponse) return res;
|
|
229
|
-
if (res instanceof Response)
|
|
234
|
+
if (res instanceof Response) {
|
|
235
|
+
const nextResponse = new next_server_js.NextResponse(res.body, {
|
|
236
|
+
status: res.status,
|
|
237
|
+
statusText: res.statusText,
|
|
238
|
+
headers: res.headers,
|
|
239
|
+
url: res.url
|
|
240
|
+
});
|
|
241
|
+
try {
|
|
242
|
+
/* v8 ignore else -- @preserve */
|
|
243
|
+
if (!(0, _monocloud_auth_node_core_internal.isPresent)(nextResponse.url)) nextResponse.url = res.url;
|
|
244
|
+
} catch {}
|
|
245
|
+
return nextResponse;
|
|
246
|
+
}
|
|
230
247
|
return new next_server_js.NextResponse();
|
|
231
248
|
};
|
|
232
249
|
const getMonoCloudCookieReqRes = (req, resOrCtx) => {
|
|
@@ -442,7 +459,7 @@ var MonoCloudNextClient = class {
|
|
|
442
459
|
constructor(options) {
|
|
443
460
|
const opt = {
|
|
444
461
|
...options ?? {},
|
|
445
|
-
userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.
|
|
462
|
+
userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.5`,
|
|
446
463
|
debugger: (options === null || options === void 0 ? void 0 : options.debugger) ?? "@monocloud:auth-nextjs"
|
|
447
464
|
};
|
|
448
465
|
this.registerPublicEnvVariables();
|
|
@@ -561,7 +578,7 @@ var MonoCloudNextClient = class {
|
|
|
561
578
|
return redirect(signInRoute.toString());
|
|
562
579
|
}
|
|
563
580
|
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)) {
|
|
564
|
-
if (options.
|
|
581
|
+
if (options.onGroupAccessDenied) return options.onGroupAccessDenied({
|
|
565
582
|
...params,
|
|
566
583
|
user: session.user
|
|
567
584
|
});
|
|
@@ -603,11 +620,11 @@ var MonoCloudNextClient = class {
|
|
|
603
620
|
} };
|
|
604
621
|
}
|
|
605
622
|
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)) {
|
|
606
|
-
var _options$
|
|
607
|
-
const customProps$1 = await ((_options$
|
|
623
|
+
var _options$onGroupAcces;
|
|
624
|
+
const customProps$1 = await ((_options$onGroupAcces = options.onGroupAccessDenied) === null || _options$onGroupAcces === void 0 ? void 0 : _options$onGroupAcces.call(options, {
|
|
608
625
|
...context,
|
|
609
626
|
user: session.user
|
|
610
|
-
})) ?? { props: {
|
|
627
|
+
})) ?? { props: { groupAccessDenied: true } };
|
|
611
628
|
return {
|
|
612
629
|
...customProps$1,
|
|
613
630
|
props: { ...customProps$1.props ?? {} }
|
|
@@ -649,8 +666,8 @@ var MonoCloudNextClient = class {
|
|
|
649
666
|
return mergeResponse([res, next_server_js.NextResponse.json({ message: "unauthorized" }, { status: 401 })]);
|
|
650
667
|
}
|
|
651
668
|
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)) {
|
|
652
|
-
if (options.
|
|
653
|
-
const result = await options.
|
|
669
|
+
if (options.onGroupAccessDenied) {
|
|
670
|
+
const result = await options.onGroupAccessDenied(req, ctx, session.user);
|
|
654
671
|
if (result instanceof next_server_js.NextResponse) return mergeResponse([res, result]);
|
|
655
672
|
return mergeResponse([res, new next_server_js.NextResponse(result.body, result)]);
|
|
656
673
|
}
|
|
@@ -667,7 +684,7 @@ var MonoCloudNextClient = class {
|
|
|
667
684
|
return res.status(401).json({ message: "unauthorized" });
|
|
668
685
|
}
|
|
669
686
|
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)) {
|
|
670
|
-
if (options.
|
|
687
|
+
if (options.onGroupAccessDenied) return options.onGroupAccessDenied(req, res, session.user);
|
|
671
688
|
return res.status(403).json({ message: "forbidden" });
|
|
672
689
|
}
|
|
673
690
|
return handler(req, res);
|
|
@@ -731,10 +748,9 @@ var MonoCloudNextClient = class {
|
|
|
731
748
|
return mergeResponse([nxtResp, next_server_js.NextResponse.redirect(signInRoute)]);
|
|
732
749
|
}
|
|
733
750
|
const groupsClaim = (options === null || options === void 0 ? void 0 : options.groupsClaim) ?? process.env.MONOCLOUD_AUTH_GROUPS_CLAIM;
|
|
734
|
-
const onAccessDenied = options === null || options === void 0 ? void 0 : options.onAccessDenied;
|
|
735
751
|
if (allowedGroups && !(0, _monocloud_auth_node_core_utils.isUserInGroup)(session.user, allowedGroups, groupsClaim)) {
|
|
736
|
-
if (
|
|
737
|
-
const result = await
|
|
752
|
+
if (options === null || options === void 0 ? void 0 : options.onGroupAccessDenied) {
|
|
753
|
+
const result = await options.onGroupAccessDenied(req, evt, session.user);
|
|
738
754
|
if (result instanceof next_server_js.NextResponse) return mergeResponse([nxtResp, result]);
|
|
739
755
|
if (result) return mergeResponse([nxtResp, new next_server_js.NextResponse(result.body, result)]);
|
|
740
756
|
return next_server_js.NextResponse.next(nxtResp);
|