@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.d.mts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { _ as ProtectPagePageOptions, a as GroupOptions, b as RedirectToSignInOptions, c as MonoCloudAuthOptions, d as PageRouterApiOnAccessDeniedHandler, f as ProtectApiAppOptions, g as ProtectPagePageOnAccessDeniedType, h as ProtectOptions, i as ExtraAuthParams, l as MonoCloudMiddlewareOptions, m as ProtectAppPageOptions, n as AppRouterApiOnAccessDeniedHandler, o as IsUserInGroupOptions, p as ProtectApiPageOptions, r as AppRouterPageHandler, s as MonoCloudAuthHandler, t as AppRouterApiHandlerFn, u as NextMiddlewareResult, v as ProtectPagePageReturnType, x as RedirectToSignOutOptions, y as ProtectedAppServerComponent } from "./types-
|
|
1
|
+
import { _ as ProtectPagePageOptions, a as GroupOptions, b as RedirectToSignInOptions, c as MonoCloudAuthOptions, d as PageRouterApiOnAccessDeniedHandler, f as ProtectApiAppOptions, g as ProtectPagePageOnAccessDeniedType, h as ProtectOptions, i as ExtraAuthParams, l as MonoCloudMiddlewareOptions, m as ProtectAppPageOptions, n as AppRouterApiOnAccessDeniedHandler, o as IsUserInGroupOptions, p as ProtectApiPageOptions, r as AppRouterPageHandler, s as MonoCloudAuthHandler, t as AppRouterApiHandlerFn, u as NextMiddlewareResult, v as ProtectPagePageReturnType, x as RedirectToSignOutOptions, y as ProtectedAppServerComponent } from "./types-Cx32VRoI.mjs";
|
|
2
2
|
import { AccessToken, GetTokensOptions, GetTokensOptions as GetTokensOptions$1, MonoCloudAuthBaseError, MonoCloudCoreClient, MonoCloudHttpError, MonoCloudOPError, MonoCloudOidcClient, MonoCloudOptions, MonoCloudOptions as MonoCloudOptions$1, MonoCloudSession, MonoCloudSession as MonoCloudSession$1, MonoCloudTokenError, MonoCloudTokens, MonoCloudTokens as MonoCloudTokens$1, MonoCloudUser, MonoCloudValidationError } from "@monocloud/auth-node-core";
|
|
3
3
|
import { NextFetchEvent, NextMiddleware, NextProxy, NextRequest, NextResponse } from "next/server.js";
|
|
4
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
5
4
|
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next/types";
|
|
6
5
|
import { ParsedUrlQuery } from "node:querystring";
|
|
6
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
7
7
|
|
|
8
8
|
//#region src/monocloud-next-client.d.ts
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* The MonoCloud Next.js Client.
|
|
12
11
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { NextRequest, NextResponse } from "next/server.js";
|
|
|
3
3
|
import { ensureLeadingSlash, isAbsoluteUrl, isPresent } from "@monocloud/auth-node-core/internal";
|
|
4
4
|
import { isUserInGroup } from "@monocloud/auth-node-core/utils";
|
|
5
5
|
import { serialize } from "cookie";
|
|
6
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
7
6
|
|
|
8
7
|
//#region src/requests/monocloud-app-router-request.ts
|
|
9
8
|
var MonoCloudAppRouterRequest = class {
|
|
@@ -219,6 +218,12 @@ var MonoCloudCookieRequest = class {
|
|
|
219
218
|
const isMonoCloudRequest = (req) => req instanceof MonoCloudAppRouterRequest || req instanceof MonoCloudPageRouterRequest || req instanceof MonoCloudCookieRequest;
|
|
220
219
|
const isMonoCloudResponse = (res) => res instanceof MonoCloudAppRouterResponse || res instanceof MonoCloudPageRouterResponse || res instanceof MonoCloudCookieResponse;
|
|
221
220
|
const isAppRouter = (req) => req instanceof Request || req.headers instanceof Headers || typeof req.bodyUsed === "boolean";
|
|
221
|
+
const isNodeRequest = (req) => {
|
|
222
|
+
return !!(req && typeof req === "object" && "headers" in req && !("bodyUsed" in req) && typeof req.on === "function");
|
|
223
|
+
};
|
|
224
|
+
const isNodeResponse = (res) => {
|
|
225
|
+
return !!(res && typeof res === "object" && "setHeader" in res && typeof res.setHeader === "function" && "end" in res && typeof res.end === "function");
|
|
226
|
+
};
|
|
222
227
|
const getNextRequest = (req) => {
|
|
223
228
|
if (req instanceof NextRequest) return req;
|
|
224
229
|
return new NextRequest(req.url, {
|
|
@@ -252,7 +257,7 @@ const getMonoCloudCookieReqRes = (req, resOrCtx) => {
|
|
|
252
257
|
request = new MonoCloudAppRouterRequest(getNextRequest(req));
|
|
253
258
|
response = resOrCtx instanceof Response ? new MonoCloudAppRouterResponse(getNextResponse(resOrCtx)) : new MonoCloudCookieResponse();
|
|
254
259
|
} else {
|
|
255
|
-
if (!(req
|
|
260
|
+
if (!isNodeRequest(req) || !isNodeResponse(resOrCtx)) throw new MonoCloudValidationError$1("Invalid pages router request and response");
|
|
256
261
|
request = new MonoCloudPageRouterRequest(req);
|
|
257
262
|
response = new MonoCloudPageRouterResponse(resOrCtx);
|
|
258
263
|
}
|
|
@@ -458,7 +463,7 @@ var MonoCloudNextClient = class {
|
|
|
458
463
|
constructor(options) {
|
|
459
464
|
const opt = {
|
|
460
465
|
...options ?? {},
|
|
461
|
-
userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.
|
|
466
|
+
userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.6`,
|
|
462
467
|
debugger: (options === null || options === void 0 ? void 0 : options.debugger) ?? "@monocloud:auth-nextjs"
|
|
463
468
|
};
|
|
464
469
|
this.registerPublicEnvVariables();
|
|
@@ -595,10 +600,10 @@ var MonoCloudNextClient = class {
|
|
|
595
600
|
if (!session) {
|
|
596
601
|
var _options$authParams10, _options$authParams11, _options$authParams12, _options$authParams13, _options$authParams14, _options$authParams15, _options$authParams16, _options$authParams17, _options$authParams18;
|
|
597
602
|
if (options === null || options === void 0 ? void 0 : options.onAccessDenied) {
|
|
598
|
-
const customProps
|
|
603
|
+
const customProps = await options.onAccessDenied({ ...context });
|
|
599
604
|
return {
|
|
600
|
-
...customProps
|
|
601
|
-
props: { ...(customProps
|
|
605
|
+
...customProps ?? {},
|
|
606
|
+
props: { ...(customProps === null || customProps === void 0 ? void 0 : customProps.props) ?? {} }
|
|
602
607
|
};
|
|
603
608
|
}
|
|
604
609
|
const { routes, appUrl } = this.getOptions();
|
|
@@ -620,13 +625,13 @@ var MonoCloudNextClient = class {
|
|
|
620
625
|
}
|
|
621
626
|
if ((options === null || options === void 0 ? void 0 : options.groups) && !isUserInGroup(session.user, options.groups, options.groupsClaim ?? process.env.MONOCLOUD_AUTH_GROUPS_CLAIM, options.matchAll)) {
|
|
622
627
|
var _options$onGroupAcces;
|
|
623
|
-
const customProps
|
|
628
|
+
const customProps = await ((_options$onGroupAcces = options.onGroupAccessDenied) === null || _options$onGroupAcces === void 0 ? void 0 : _options$onGroupAcces.call(options, {
|
|
624
629
|
...context,
|
|
625
630
|
user: session.user
|
|
626
631
|
})) ?? { props: { groupAccessDenied: true } };
|
|
627
632
|
return {
|
|
628
|
-
...customProps
|
|
629
|
-
props: { ...customProps
|
|
633
|
+
...customProps,
|
|
634
|
+
props: { ...customProps.props ?? {} }
|
|
630
635
|
};
|
|
631
636
|
}
|
|
632
637
|
const customProps = (options === null || options === void 0 ? void 0 : options.getServerSideProps) ? await options.getServerSideProps(context) : {};
|
|
@@ -799,7 +804,7 @@ var MonoCloudNextClient = class {
|
|
|
799
804
|
({request, response} = getMonoCloudCookieReqRes(args[0], void 0));
|
|
800
805
|
options = args[1];
|
|
801
806
|
}
|
|
802
|
-
else if (args.length === 2 && args[0]
|
|
807
|
+
else if (args.length === 2 && isNodeRequest(args[0]) && isNodeResponse(args[1])) ({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
|
|
803
808
|
else {
|
|
804
809
|
({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
|
|
805
810
|
options = args[2];
|
|
@@ -912,7 +917,7 @@ var MonoCloudNextClient = class {
|
|
|
912
917
|
groups = args[1];
|
|
913
918
|
options = args[2];
|
|
914
919
|
}
|
|
915
|
-
if (args[0]
|
|
920
|
+
if (isNodeRequest(args[0]) && isNodeResponse(args[1])) {
|
|
916
921
|
({request, response} = getMonoCloudCookieReqRes(args[0], args[1]));
|
|
917
922
|
groups = args[2];
|
|
918
923
|
}
|