This guide shows how to trigger sign-in, sign-out, and sign-up flows in a Next.js application using MonoCloud.
MonoCloud provides two ways to start authentication flows:
Use these helpers when you want to explicitly control authentication flows rather than relying on automatic redirects from protected routes.
Use these APIs when:
MonoCloud provides UI components for common authentication actions such as signing in, signing out, and signing up.
These components:
<SignIn />, <SignUp />, and <SignOut /> can be rendered from both Server Components and Client Components<RedirectToSignIn /> is a Client Component only<SignIn /> renders a clickable element that redirects the user to sign in.
import { SignIn } from "@monocloud/auth-nextjs/components";
export function SignInButton() {
return <SignIn>Sign in</SignIn>;
}
With a return URL
<SignIn returnUrl="/dashboard">Sign in</SignIn>
Behavior
<SignUp /> redirects users to the MonoCloud-hosted sign-up flow.
import { SignUp } from "@monocloud/auth-nextjs/components";
export function SignUpButton() {
return <SignUp>Create account</SignUp>;
}
Use this when you want to send users directly to registration instead of sign-in.
<SignOut /> signs the user out and redirects them to the configured post-logout URL.
import { SignOut } from "@monocloud/auth-nextjs/components";
export function SignOutButton() {
return <SignOut>Sign out</SignOut>;
}
Behavior
<RedirectToSignIn /> immediately redirects the user to the MonoCloud-hosted sign-in page when rendered.
<RedirectToSignIn /> is a Client Component only and must be rendered from a file with "use client".
Use this when:
"use client";
import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
export function RequireAuth() {
return <RedirectToSignIn />;
}
With a return URL
<RedirectToSignIn returnUrl="/dashboard" />
Behavior
For full control over navigation, use the redirect helpers provided by the SDK.
These helpers work only in the Next.js App Router and can be used from:
Redirects the user to the MonoCloud sign-in flow.
This helper is only supported in the Next.js App Router.
await redirectToSignIn();
Common use cases
Signs the user out and redirects them back to your app.
This helper is only supported in the Next.js App Router.
await redirectToSignOut();
Use this when sign-out is triggered from logic instead of UI.
Both helpers accept options to override where the user is sent after authentication.
await redirectToSignIn({
returnUrl: "/dashboard",
});
await redirectToSignOut({
returnUrl: "/dashboard",
});
"use server";
import { redirectToSignIn } from "@monocloud/auth-nextjs";
export async function startSignIn() {
await redirectToSignIn({
returnUrl: "/dashboard",
});
}
The Server Action does not complete—the redirect happens immediately.
| Use case | Recommended |
|---|---|
| Clickable sign-in button | <SignIn /> |
| Clickable sign-up button | <SignUp /> |
| Clickable sign-out button | <SignOut /> |
| Immediate redirect on render | <RedirectToSignIn /> |
| Server-side redirect | redirectToSignIn(), redirectToSignOut() |
Continue securing your application: