MonoCloud Authentication SDK
    Preparing search index...
    • Creates a Next.js authentication middleware that protects routes.

      By default, all routes matched by config.matcher are protected unless configured otherwise.

      Parameters

      • Optionaloptions: MonoCloudMiddlewareOptions

        Optional configuration that controls how authentication is enforced (for example, redirect behavior, route matching, or custom handling of unauthenticated requests).

      Returns NextMiddleware

      Returns a Next.js middleware result, such as a NextResponse, redirect, or undefined to continue processing.

      import { authMiddleware } from "@monocloud/auth-nextjs";

      export default authMiddleware();

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };
      import { authMiddleware } from "@monocloud/auth-nextjs";

      export default authMiddleware({
      protectedRoutes: ["/api/admin", "^/api/protected(/.*)?$"],
      });

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };
      import { authMiddleware } from "@monocloud/auth-nextjs";

      export default authMiddleware({
      protectedRoutes: [],
      });

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };
      import { authMiddleware } from "@monocloud/auth-nextjs";

      export default authMiddleware({
      protectedRoutes: (req) => {
      return req.nextUrl.pathname.startsWith("/api/protected");
      },
      });

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };
      import { authMiddleware } from "@monocloud/auth-nextjs";

      export default authMiddleware({
      protectedRoutes: [
      {
      groups: ["admin", "editor", "537e7c3d-a442-4b5b-b308-30837aa045a4"],
      routes: ["/internal", "/api/internal(.*)"],
      },
      ],
      });

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };
    • Executes the authentication middleware manually.

      Intended for advanced scenarios where the middleware is composed within custom logic.

      Parameters

      • request: NextRequest

        Incoming Next.js middleware request used to resolve authentication state.

      • event: NextFetchEvent

        Next.js middleware event providing lifecycle hooks such as waitUntil.

      Returns NextMiddlewareResult | Promise<NextMiddlewareResult>

      Returns a Next.js middleware result (NextResponse, redirect, or undefined to continue processing).

      import { authMiddleware } from "@monocloud/auth-nextjs";
      import { NextFetchEvent, NextRequest, NextResponse } from "next/server";

      export default function customMiddleware(req: NextRequest, evt: NextFetchEvent) {
      if (req.nextUrl.pathname.startsWith("/api/protected")) {
      return authMiddleware(req, evt);
      }

      return NextResponse.next();
      }

      export const config = {
      matcher: [
      "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
      ],
      };