MonoCloud Authentication SDK
    Preparing search index...
    • Ensures the current user is authenticated. If not, redirects to the sign-in flow.

      App Router only. Intended for Server Components, Route Handlers, and Server Actions.

      Parameters

      • Optionaloptions: ProtectOptions

        Optional configuration for redirect behavior (for example, return URL or sign-in parameters).

      Returns Promise<void>

      Resolves if the user is authenticated; otherwise triggers a redirect.

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

      export default async function Home() {
      await protect();

      return <>You are signed in.</>;
      }
      "use server";

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

      export async function getMessage() {
      await protect();

      return { secret: "sssshhhhh!!!" };
      }
      import { protect } from "@monocloud/auth-nextjs";
      import { NextResponse } from "next/server";

      export const GET = async () => {
      await protect();

      return NextResponse.json({ secret: "ssshhhh!!!" });
      };