Protect a route
A protected route detects that the visitor is not authenticated and sends them to Clerk's configured sign-in destination.
Clerk · Pipe
redirectToSignIn navigates to the sign-in URL configured in the application's instance. It returns a promise that can be awaited for navigation completion.
Call redirectToSignIn when an unauthenticated user must reach the sign-in URL configured for the application instance. It performs navigation through Clerk's navigation mechanism and returns a promise that can be awaited when code needs to observe navigation completion; the promise's resolved value is framework-dependent.
function redirectToSignIn(opts?: SignInRedirectOptions): Promise<unknown>| Name | Type | Description |
|---|---|---|
opts | SignInRedirectOptions | Optional redirect configuration supplied to the sign-in navigation. |
Promise<unknown>
import { redirectToSignIn } from '@clerk/nextjs'
export default function ProtectedPage() {
redirectToSignIn()
return null
}Redirects the current request to the configured sign-in URL.
A protected route detects that the visitor is not authenticated and sends them to Clerk's configured sign-in destination.
Application code needs to wait until Clerk finishes navigation before continuing framework-specific work.
redirectToSignIn(opts?: SignInRedirectOptions) returns Promise<unknown>. It redirects to the sign-in URL configured in the application's instance and uses navigate() internally.
Follow-up: Why might code await the result? To observe when navigation finishes, but not to consume a stable return value.
The destination is controlled by the sign-in URL configured in the application instance. The method performs navigation rather than merely opening a sign-in UI.
Follow-up: How should destination configuration be handled? Configure the application's sign-in URL instead of assuming a hard-coded destination.
The method uses navigate() under the hood, and its returned promise can be awaited to listen for navigation completion. The promise's inner value is not a portable API contract.
Follow-up: What should a cross-framework integration avoid? Branching on the resolved value, because it can change with the framework.
SignInRedirectOptionsnavigate()openSignIn()<SignIn />