@monocloud/auth-nextjs 0.1.4 → 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/index.d.mts CHANGED
@@ -1,4 +1,4 @@
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-DOfZTKa6.mjs";
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-CsBjAJce.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
4
  import { IncomingMessage, ServerResponse } from "node:http";
@@ -268,8 +268,8 @@ declare class MonoCloudNextClient {
268
268
  *
269
269
  * Restricts access to server-rendered pages in your Next.js App Router application, ensures that only authenticated (and optionally authorized) users can view the page.
270
270
  *
271
- * **Note⚠️ - When using groups to protect a page, 'Access Denied' is rendered by default when the user does not have
272
- * enough permissions. To display a custom component, pass the `onAccessDenied` parameter.**
271
+ * **Note⚠️ - When using groups to protect a page, 'Access Denied' is rendered by default when the user does not belong to the groups.
272
+ * To display a custom component, pass the `onGroupAccessDenied` parameter.**
273
273
  *
274
274
  * @param component The App Router server component that protectPage wraps and secures
275
275
  * @param options App Router `protectPage()` configuration options
@@ -308,9 +308,9 @@ declare class MonoCloudNextClient {
308
308
  *
309
309
  * Restricts access to server-rendered pages in your Next.js Pages Router application, ensures that only authenticated (and optionally authorized) users can view the page.
310
310
  *
311
- * **Note⚠️ - When using groups to protect a page, the page will be rendered even if the user does not have
312
- * enough permissions. You should check the props for `accessDenied` boolean value to determine whether the user is
313
- * allowed to accesss the page. Alternatively, you can pass `onAccessDenied` parameter to return custom props.**
311
+ * **Note⚠️ - When using groups to protect a page, the page will be rendered even if the user does not belong to the groups.
312
+ * You should check the props for `groupAccessDenied` boolean value to determine whether the user is
313
+ * allowed to access the page. Alternatively, you can pass `onGroupAccessDenied` parameter to return custom props.**
314
314
  *
315
315
  * @param options Pages Router `protectPage()` configuration options
316
316
  *
@@ -764,8 +764,12 @@ declare class MonoCloudNextClient {
764
764
  * @example SSR Component
765
765
  *
766
766
  * ```typescript
767
- * import { monoCloud } from "@/lib/monocloud";
768
- * import type { GetServerSideProps, InferGetServerSidePropsType } from "next";
767
+ * import { monoCloud } from "@/monocloud";
768
+ * import type {
769
+ * GetServerSideProps,
770
+ * GetServerSidePropsContext,
771
+ * InferGetServerSidePropsType,
772
+ * } from "next";
769
773
  *
770
774
  * type HomeProps = InferGetServerSidePropsType<typeof getServerSideProps>;
771
775
  *
@@ -773,15 +777,20 @@ declare class MonoCloudNextClient {
773
777
  * return <pre>Session: {JSON.stringify(session, null, 2)}</pre>;
774
778
  * }
775
779
  *
776
- * export const getServerSideProps: GetServerSideProps = async (context) => {
777
- * const session = await monoCloud.getSession(context.req, context.res);
780
+ * export const getServerSideProps = (async (
781
+ * context: GetServerSidePropsContext,
782
+ * ) => {
783
+ * const session = await monoCloud.getSession(
784
+ * context.req,
785
+ * context.res,
786
+ * );
778
787
  *
779
788
  * return {
780
789
  * props: {
781
790
  * session: session ?? null,
782
791
  * },
783
792
  * };
784
- * };
793
+ * }) satisfies GetServerSideProps;
785
794
  * ```
786
795
  */
787
796
  getSession(req: NextApiRequest | IncomingMessage, res: NextApiResponse | ServerResponse<IncomingMessage>): Promise<MonoCloudSession$1 | undefined>;
@@ -868,7 +877,7 @@ declare class MonoCloudNextClient {
868
877
  *
869
878
  * The default token is an access token with scopes set through `MONOCLOUD_AUTH_SCOPES` or
870
879
  * `options.defaultAuthParams.scopes`, and resources set through `MONOCLOUD_AUTH_RESOURCE` or
871
- * `options.defaultAuthParams.resource`. This token is refreshed when calling getTokens without parameters.
880
+ * `options.defaultAuthParams.resource`. This token is refreshed when calling getTokens without resource and scopes parameters.
872
881
  *
873
882
  * ```typescript
874
883
  * import { NextResponse } from "next/server";
package/dist/index.mjs CHANGED
@@ -458,7 +458,7 @@ var MonoCloudNextClient = class {
458
458
  constructor(options) {
459
459
  const opt = {
460
460
  ...options ?? {},
461
- userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.4`,
461
+ userAgent: (options === null || options === void 0 ? void 0 : options.userAgent) ?? `@monocloud/auth-nextjs@0.1.5`,
462
462
  debugger: (options === null || options === void 0 ? void 0 : options.debugger) ?? "@monocloud:auth-nextjs"
463
463
  };
464
464
  this.registerPublicEnvVariables();
@@ -577,7 +577,7 @@ var MonoCloudNextClient = class {
577
577
  return redirect(signInRoute.toString());
578
578
  }
579
579
  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)) {
580
- if (options.onAccessDenied) return options.onAccessDenied({
580
+ if (options.onGroupAccessDenied) return options.onGroupAccessDenied({
581
581
  ...params,
582
582
  user: session.user
583
583
  });
@@ -619,11 +619,11 @@ var MonoCloudNextClient = class {
619
619
  } };
620
620
  }
621
621
  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
- var _options$onAccessDeni;
623
- const customProps$1 = await ((_options$onAccessDeni = options.onAccessDenied) === null || _options$onAccessDeni === void 0 ? void 0 : _options$onAccessDeni.call(options, {
622
+ var _options$onGroupAcces;
623
+ const customProps$1 = await ((_options$onGroupAcces = options.onGroupAccessDenied) === null || _options$onGroupAcces === void 0 ? void 0 : _options$onGroupAcces.call(options, {
624
624
  ...context,
625
625
  user: session.user
626
- })) ?? { props: { accessDenied: true } };
626
+ })) ?? { props: { groupAccessDenied: true } };
627
627
  return {
628
628
  ...customProps$1,
629
629
  props: { ...customProps$1.props ?? {} }
@@ -665,8 +665,8 @@ var MonoCloudNextClient = class {
665
665
  return mergeResponse([res, NextResponse.json({ message: "unauthorized" }, { status: 401 })]);
666
666
  }
667
667
  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)) {
668
- if (options.onAccessDenied) {
669
- const result = await options.onAccessDenied(req, ctx);
668
+ if (options.onGroupAccessDenied) {
669
+ const result = await options.onGroupAccessDenied(req, ctx, session.user);
670
670
  if (result instanceof NextResponse) return mergeResponse([res, result]);
671
671
  return mergeResponse([res, new NextResponse(result.body, result)]);
672
672
  }
@@ -683,7 +683,7 @@ var MonoCloudNextClient = class {
683
683
  return res.status(401).json({ message: "unauthorized" });
684
684
  }
685
685
  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)) {
686
- if (options.onAccessDenied) return options.onAccessDenied(req, res, session.user);
686
+ if (options.onGroupAccessDenied) return options.onGroupAccessDenied(req, res, session.user);
687
687
  return res.status(403).json({ message: "forbidden" });
688
688
  }
689
689
  return handler(req, res);
@@ -747,10 +747,9 @@ var MonoCloudNextClient = class {
747
747
  return mergeResponse([nxtResp, NextResponse.redirect(signInRoute)]);
748
748
  }
749
749
  const groupsClaim = (options === null || options === void 0 ? void 0 : options.groupsClaim) ?? process.env.MONOCLOUD_AUTH_GROUPS_CLAIM;
750
- const onAccessDenied = options === null || options === void 0 ? void 0 : options.onAccessDenied;
751
750
  if (allowedGroups && !isUserInGroup(session.user, allowedGroups, groupsClaim)) {
752
- if (onAccessDenied) {
753
- const result = await onAccessDenied(req, evt, session.user);
751
+ if (options === null || options === void 0 ? void 0 : options.onGroupAccessDenied) {
752
+ const result = await options.onGroupAccessDenied(req, evt, session.user);
754
753
  if (result instanceof NextResponse) return mergeResponse([nxtResp, result]);
755
754
  if (result) return mergeResponse([nxtResp, new NextResponse(result.body, result)]);
756
755
  return NextResponse.next(nxtResp);