Sign in

Function: protect

protect(options?: ProtectOptions): Promise<void>

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

ParameterTypeDescription
options?ProtectOptionsOptional 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.

Examples

src/app/page.tsx
import { protect } from "@monocloud/auth-nextjs";

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

  return <>You are signed in.</>;
}
© 2024 MonoCloud. All rights reserved.