Require sign-in
Protect a page or route by sending signed-out visitors to authentication.
Clerk · Component
RedirectToSignIn sends unauthenticated users to the sign-in URL configured in the Clerk application. Its navigation behaves like a server-side redirect and replaces the current history entry.
Render this control component when an unauthenticated visitor should be sent to the application's configured sign-in page. Navigation behaves like a server redirect and replaces the current history entry rather than leaving it available as a back-navigation destination.
<RedirectToSignIn />import { Show, RedirectToSignIn, UserButton } from '@clerk/react'
export default function Page() {
return (
<>
<Show when="signed-in">
<UserButton />
</Show>
<Show when="signed-out">
<RedirectToSignIn />
</Show>
</>
)
}Displays the user button for authenticated users and redirects unauthenticated users to the configured sign-in URL.
Protect a page or route by sending signed-out visitors to authentication.
Use Clerk's authentication-state rendering to show signed-in content and redirect everyone else.
It navigates to the sign-in URL configured for the application instance. Its navigation has server-side 3xx-like behavior and overrides the current history location.
Follow-up: How would you avoid redirecting authenticated users? Render it only in a signed-out branch, such as a Show component whose condition is signed-out.
In React, import it from @clerk/react and render it as a JSX component. It is a control component intended to be composed with Clerk's authentication-state controls.
Follow-up: What complementary control can render authenticated-only content? Use Show with when="signed-in", or the related signed-in control documented by Clerk.
It redirects to the sign-in URL configured in the Clerk application instance rather than taking a destination URL in the component markup. The documented component declaration is simply <RedirectToSignIn />.
Follow-up: What should be configured when the default sign-in destination is not the desired route? Change the sign-in URL in the application's Clerk configuration so the component targets that configured location.
ShowUserButtonSignInRedirectToSignUpSignedInSignedOut