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.
| Parameter | Type | Description |
|---|---|---|
options? | ProtectOptions | Optional configuration for redirect behavior (for example, return URL or sign-in parameters). |
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.</>;
}