-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Router sign-in-or-up docs (#1821)
- Loading branch information
1 parent
e35aac7
commit da11741
Showing
3 changed files
with
87 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
docs/references/react-router/custom-sign-in-or-up-page.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: Build your own sign-in-or-up page for your React Router app with Clerk | ||
description: Learn how to add a custom sign-in-or-up page to your React Router app with Clerk's prebuilt components. | ||
--- | ||
|
||
This guide shows you how to use the [`<SignIn />`](/docs/components/authentication/sign-in) component with the [React Router Splat route](https://reactrouter.com/start/framework/routing#splats) in order to build a custom page for your Next.js app that allows users to sign-in or sign-up within a single flow. | ||
|
||
If the prebuilt components don't meet your specific needs or if you require more control over the logic, you can rebuild the existing Clerk flows using the Clerk API. For more information, see the [custom flow guides](/docs/custom-flows/overview). | ||
|
||
<Steps> | ||
## Build a sign-in-or-up page | ||
|
||
The following example demonstrates how to render the [`<SignIn />`](/docs/components/authentication/sign-up) component to allow users to both sign-in or sign-up from a single flow. | ||
|
||
```tsx {{ filename: 'app/routes/sign-in.tsx' }} | ||
import { SignIn } from '@clerk/react-router' | ||
|
||
export default function SignInPage() { | ||
return ( | ||
<div> | ||
<h1>Sign in or up route</h1> | ||
<SignIn /> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
## Configure routes | ||
|
||
React Router expects you to define routes in [`app/routes.ts`](https://reactrouter.com/start/framework/routing). Add the previously created sign-in-or-up page to your route configuration. | ||
|
||
```tsx {{ filename: 'app/routes.ts', mark: [5] }} | ||
import { type RouteConfig, index, route } from '@react-router/dev/routes' | ||
|
||
export default [ | ||
index('routes/home.tsx'), | ||
route('sign-in/*', 'routes/sign-in.tsx'), | ||
] satisfies RouteConfig | ||
``` | ||
|
||
## Configure redirect behavior | ||
|
||
Update your environment variables to point to your custom sign-in-or-up page. Learn more about the available [environment variables](/docs/deployments/clerk-environment-variables). | ||
|
||
```env {{ filename: '.env' }} | ||
CLERK_SIGN_IN_FALLBACK_URL=/ | ||
CLERK_SIGN_IN_URL=/sign-in | ||
``` | ||
|
||
## Visit your new page | ||
|
||
Run your project with the following command: | ||
|
||
<CodeBlockTabs options={["npm", "yarn", "pnpm"]}> | ||
```bash {{ filename: 'terminal' }} | ||
npm run dev | ||
``` | ||
|
||
```bash {{ filename: 'terminal' }} | ||
yarn dev | ||
``` | ||
|
||
```bash {{ filename: 'terminal' }} | ||
pnpm dev | ||
``` | ||
</CodeBlockTabs> | ||
|
||
Visit your new custom page locally at [localhost:5173/sign-in](http://localhost:5173/sign-in). | ||
</Steps> | ||
|
||
## Next steps | ||
|
||
<Cards> | ||
- [Custom sign-up page](/docs/references/react-router/custom-sign-up-page) | ||
- Learn how to add a custom sign-up page to your React Router app with Clerk's prebuilt components. | ||
</Cards> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters