Build your own sign-in-or-up page for your React app with Clerk
This guide shows you how to use the <SignIn /> component to build a custom page that allows users to sign in or sign up within a single flow.
To set up separate sign-in and sign-up pages, follow this guide, and then follow the custom sign-up page guide
Build a sign-in-or-up page
The following example demonstrates how to render the <SignIn /> component on a dedicated page.
Create a src/sign-in.tsx file and add the following code:
import { SignIn } from '@clerk/react'
export default function SignInPage() {
return <SignIn />
}Update your src/App.tsx file to add the SignInPage() component and handle the /sign-in route.
import { Show, SignInButton, SignUpButton, UserButton, SignIn } from '@clerk/react'
function SignInPage() {
return <SignIn path="/sign-in" />
}
export default function App() {
const path = window.location.pathname
if (path === '/sign-in' || path.startsWith('/sign-in/')) {
return (
<div>
<SignInPage />
</div>
)
}
return (
<header>
<Show when="signed-out">
<SignInButton />
<SignUpButton />
</Show>
<Show when="signed-in">
<UserButton />
</Show>
</header>
)
}Update your src/main.tsx to import the sign-in page, add a route for it, and configure <ClerkProvider> with the following props:
- Set
signInUrlto tell Clerk where the<SignIn />component is being hosted. - Set
signInFallbackRedirectUrlas a fallback URL in case users visit the/sign-inroute directly. - Set
signUpFallbackRedirectUrlas a fallback URL in case users select the 'Don't have an account? Sign up' link at the bottom of the component.
Learn more about these props and how to customize Clerk's redirect behavior in the dedicated guide.
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router'
import { ClerkProvider } from '@clerk/react'
import './index.css'
import SignInPage from './sign-in.tsx'
import App from './App.tsx'
function RootLayout() {
const navigate = useNavigate()
return (
<ClerkProvider
routerPush={(to) => navigate(to)}
routerReplace={(to) => navigate(to, { replace: true })}
signInUrl="/sign-in"
signInFallbackRedirectUrl="/"
signUpFallbackRedirectUrl="/"
>
<Routes>
<Route path="/" element={<App />} />
{/* Must be a splat route (catch-all) route to handle nested paths */}
<Route path="/sign-in/*" element={<SignInPage />} />
</Routes>
</ClerkProvider>
)
}
createRoot(document.getElementById('root')!).render(
<StrictMode>
<BrowserRouter>
<RootLayout />
</BrowserRouter>
</StrictMode>,
)Update your <ClerkProvider> to add the signInUrl, signInFallbackRedirectUrl, and signUpFallbackRedirectUrl props.
- Set
signInUrlto tell Clerk where the<SignIn />component is being hosted. - Set
signInFallbackRedirectUrlas a fallback URL in case users visit the/sign-inroute directly. - Set
signUpFallbackRedirectUrlas a fallback URL in case users select the 'Don't have an account? Sign up' link at the bottom of the component.
Learn more about these props and how to customize Clerk's redirect behavior in the dedicated guide.
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { ClerkProvider } from '@clerk/react'
const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
if (!PUBLISHABLE_KEY) {
throw new Error('Add your Clerk Publishable Key to the .env file')
}
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ClerkProvider
publishableKey={PUBLISHABLE_KEY}
signInUrl="/sign-in"
signInFallbackRedirectUrl="/"
signUpFallbackRedirectUrl="/"
>
<App />
</ClerkProvider>
</React.StrictMode>,
)Visit your new page
Run your project with the following command:
npm run devpnpm run devyarn devbun run devVisit your new custom page locally at localhost:5173/sign-in.
Next steps
Learn more about Clerk components, how to use them to create custom pages, and how to use Clerk's client-side helpers using the following guides.
Create a custom sign-up page
Learn how to add a custom sign-up page to your React app with Clerk's components.
Protect content and read user data
Learn how to use Clerk's hooks to protect content and read user data in your React app.
Prebuilt components
Learn how to quickly add authentication to your app using Clerk's suite of components.
Customization & localization
Learn how to customize and localize the Clerk components.
Clerk React SDK Reference
Learn about the Clerk React SDK and how to integrate it into your app.
Feedback
Last updated on