MonoCloud Authentication SDK
    Preparing search index...
    • Wraps an App Router API route handler and ensures that only authenticated (and optionally authorized) requests can access the route.

      Intended for Next.js App Router Route Handlers.

      Parameters

      Returns AppRouterApiHandlerFn

      Returns a wrapped handler that enforces authentication (and optional authorization) before invoking the original handler.

      import { protectApi } from "@monocloud/auth-nextjs";
      import { NextResponse } from "next/server";

      export const GET = protectApi(async () => {
      return NextResponse.json({
      message: "You accessed a protected endpoint",
      });
      });
    • Wraps a Pages Router API route handler and ensures that only authenticated (and optionally authorized) requests can access the route.

      Intended for Next.js Pages Router API routes.

      Parameters

      • handler: NextApiHandler

        The route handler to protect.

      • Optionaloptions: ProtectApiPageOptions

        Optional configuration controlling authentication and authorization behavior.

      Returns NextApiHandler

      Returns a wrapped handler that enforces authentication (and optional authorization) before invoking the original handler.

      import { protectApi } from "@monocloud/auth-nextjs";
      import { NextApiRequest, NextApiResponse } from "next";

      export default protectApi(
      async (req: NextApiRequest, res: NextApiResponse) => {
      return res.json({
      message: "You accessed a protected endpoint",
      });
      }
      );