Package Exports
- @clerk/tanstack-start
- @clerk/tanstack-start/package.json
- @clerk/tanstack-start/server
Readme
@clerk/tanstack-start
Overview
Clerk is the easiest way to add authentication and user management to your TanStack Start application. Add sign up, sign in, and profile management to your application in minutes.
Getting Started
Prerequisites
- React 18 or later
- Node.js
>=18.17.0or later
Installation
npm install @clerk/tanstack-startBuild
To build the package locally with the TypeScript compiler, run:
npm run buildTo build the package in watch mode, run the following:
npm run devUsage
Make sure the following environment variables are set in a .env file:
CLERK_PUBLISHABLE_KEY=[publishable-key]
CLERK_SECRET_KEY=[backend-secret-key]You can get these from the API Keys screen in your Clerk dashboard.
To initialize Clerk with your TanStack Start application, you will need to make one modification to app/routes/_root.tsx:
- Wrap the children of the
RootComponentwith<ClerkProvider/>
import { ClerkProvider } from '@clerk/tanstack-start'
import { createRootRoute } from '@tanstack/react-router'
import { Link, Outlet, ScrollRestoration } from '@tanstack/react-router'
import { TanStackRouterDevtools } from '@tanstack/router-devtools'
import { Body, Head, Html, Meta, Scripts } from '@tanstack/start'
import * as React from 'react'
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
import { NotFound } from '~/components/NotFound'
export const Route = createRootRoute({
meta: () => [
{
charSet: 'utf-8',
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
],
errorComponent: (props) => {
return (
<RootDocument>
<DefaultCatchBoundary {...props} />
</RootDocument>
)
},
notFoundComponent: () => <NotFound />,
component: RootComponent,
})
function RootComponent() {
return (
<ClerkProvider>
<RootDocument>
<Outlet />
</RootDocument>
</ClerkProvider>
)
}
function RootDocument({ children }: { children: React.ReactNode }) { ... }Also you will need to make on more modification to app/ssr.tsx:
- Wrap the
createRequestHandlerwithcreateClerkHandler
import { createRequestHandler, defaultStreamHandler } from '@tanstack/start/server';
import { getRouterManifest } from '@tanstack/start/router-manifest';
import { createRouter } from './router';
import { createClerkHandler } from '@clerk/tanstack-start/server';
const handler = createRequestHandler({
createRouter,
getRouterManifest,
});
const clerkHandler = createClerkHandler(handler);
/*
* // You can also override Clerk options by passing an object as second argument
* const clerkHandler = createClerkHandler(handler, {
* afterSignInUrl: '/dashboard',
* });
*
*/
export default clerkHandler(defaultStreamHandler);After those changes are made, you can use Clerk components in your routes.
For example, in app/routes/index.tsx:
import { SignIn, SignedIn, SignedOut, UserButton } from '@clerk/tanstack-start';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: Home,
});
function Home() {
return (
<div className='p-2'>
<h1>Hello Clerk!</h1>
<SignedIn>
<UserButton />
</SignedIn>
<SignedOut>
<SignIn />
</SignedOut>
</div>
);
}Support
You can get in touch with us in any of the following ways:
- Join our official community Discord server
- Create a GitHub Discussion
- Contact options listed on our Support page
Contributing
We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines) .
Security
@clerk/nextjs follows good practices of security, but 100% security cannot be assured.
@clerk/nextjs is provided "as is" without any warranty. Use at your own risk.
For more information and to report security issues, please refer to our security documentation.
License
This project is licensed under the MIT license.
See LICENSE for more information.