Clerk is the easiest way to add authentication and user management to your application. Add sign up, sign in, and profile management to your application in minutes.
clerk-solidjs v3 targets Solid 2 and tracks Clerk Core 3 (@clerk/react 6.x):
✔ Prebuilt components, including <PricingTable />, <APIKeys />, <UserAvatar />, the session task components, and OAuth consent
✔ Custom pages and menu items for <UserProfile />, <OrganizationProfile />, <UserButton />, and <OrganizationSwitcher />
✔ Control components such as <Show />, <ClerkLoaded />, and <ClerkDegraded />
✔ Hooks*, including the signal-based useSignIn(), useSignUp(), and useWaitlist()
✔ Billing components and hooks under clerk-solidjs/experimental
✔ Server rendering with Solid 2 start mode: middleware, auth(), and SSR auth state
* Hooks return accessors, and hooks that take parameters take an accessor so they stay reactive:
const { isSignedIn, userId } = useAuth();
isSignedIn(); // read like any other accessor
useOrganizationList(() => ({ userMemberships: { infinite: true } }));solid-jsand@solidjs/web>=2- For server rendering:
@solidjs/vite-plugin>=3in start mode, and@solidjs/router>=2 - Node.js
>=20.19
Using Solid 1 or SolidStart? Stay on clerk-solidjs@2.
npm install clerk-solidjs
# or
yarn add clerk-solidjs
# or
pnpm add clerk-solidjs
# or
bun add clerk-solidjsWrap your application in a <ClerkProvider />. With Vite, VITE_CLERK_PUBLISHABLE_KEY is read automatically, or pass publishableKey explicitly.
// src/App.tsx
import { ClerkProvider } from 'clerk-solidjs';
import { Loading } from 'solid-js';
export default function App() {
return (
<ClerkProvider publishableKey={import.meta.env.VITE_CLERK_PUBLISHABLE_KEY}>
<Loading>
<Home />
</Loading>
</ClerkProvider>
);
}Then use components and hooks anywhere below the provider:
import {
ClerkLoaded,
ClerkLoading,
Show,
SignInButton,
UserButton,
useAuth
} from 'clerk-solidjs';
export default function Home() {
const { userId } = useAuth();
return (
<div>
<ClerkLoading>
<p>Loading...</p>
</ClerkLoading>
<ClerkLoaded>
<Show when="signed-in">
<UserButton />
<p>Welcome, {userId()}</p>
</Show>
<Show when="signed-out">
<SignInButton />
</Show>
</ClerkLoaded>
</div>
);
}<Show /> also gates on roles, permissions, features, and plans:
<Show when={{ role: 'org:admin' }} fallback={<p>Admins only</p>}>
<AdminPanel />
</Show><UserProfile>
<UserProfile.Page label="Custom" url="custom" labelIcon={<Icon />}>
<h1>Custom page</h1>
</UserProfile.Page>
<UserProfile.Link label="Home" url="/" labelIcon={<HomeIcon />} />
</UserProfile>
<UserButton>
<UserButton.MenuItems>
<UserButton.Action label="Help" labelIcon={<Icon />} onClick={openHelp} />
<UserButton.Link label="Docs" href="/docs" labelIcon={<Icon />} />
</UserButton.MenuItems>
</UserButton>Custom page content renders in your component tree's context, so it can use your providers and router.
The clerk-solidjs/start and clerk-solidjs/start/server entry points integrate with @solidjs/vite-plugin start mode. Set CLERK_SECRET_KEY and VITE_CLERK_PUBLISHABLE_KEY in your environment.
// vite.config.ts
import solid from '@solidjs/vite-plugin';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
solid({
start: { middleware: './src/middleware.ts' },
ssr: true,
serverFunctions: true
})
]
});// src/middleware.ts
import { clerkMiddleware } from 'clerk-solidjs/start/server';
export default [
clerkMiddleware()
// ... other middleware
];clerkMiddleware(options) accepts the usual Clerk options (secretKey, publishableKey, signInUrl, authorizedParties, organizationSyncOptions, ...) or a callback that returns them per request.
Import ClerkProvider from clerk-solidjs/start and render it inside your router. It renders the request's auth state on the server, hands it to the browser for hydration, and navigates with Solid Router.
// src/App.tsx
import { ClerkProvider } from 'clerk-solidjs/start';
import { Loading } from 'solid-js';
import { Router } from './router';
export default function App() {
return (
<Router>
{(props) => (
<ClerkProvider>
<Loading>{props.children}</Loading>
</ClerkProvider>
)}
</Router>
);
}clerk-solidjs/start re-exports every component and hook, so import them from there in start-mode apps.
With clerkMiddleware in place, auth() returns the request's auth object in server functions and API routes:
import { auth } from 'clerk-solidjs/start/server';
export async function getProjects() {
'use server';
const { isAuthenticated, userId } = await auth();
if (!isAuthenticated) {
throw new Error('You must be signed in');
}
// ...
}getRequestEvent().locals.auth is typed as well: it is a function returning the auth object.
v3 is a major release:
- Solid 2 only.
solid-js,@solidjs/web, and (for/start)@solidjs/router2 are peer dependencies. Solid 1 and SolidStart users should stay on v2. - SolidStart → start mode.
clerk-solidjs/starttargets@solidjs/vite-pluginstart mode.clerkMiddleware()is now fetch-style middleware (export it from your middleware module instead of wrapping it increateMiddleware), andauth()is async. - Clerk Core 3.
<SignedIn>,<SignedOut>, and<Protect>are replaced by<Show>.useSignIn()anduseSignUp()are the new signal-based hooks; the previous resource-based ones are available fromclerk-solidjs/legacy. The prebuilt UI now loads@clerk/uifrom Clerk's CDN (or passuifrom@clerk/uito bundle it). - Removed the deprecated
clerk-solidjs/serverentry point (useclerk-solidjs/start/server) and CommonJS builds. useAuth()now also returnssessionStatusandsessionClaims, andhas()supports features, plans, and reverification checks.- Node.js
>=20.19(was>=18): Clerk Core 3 needs Node 20, and Vite 8, which start mode runs on, needs 20.19. - Not supported yet: the Stripe
PaymentElementpieces of the billing API (they need Stripe's React bindings), and portal containers (UNSAFE_PortalProvider/getContainer, a React portal feature).
You can get in touch in any of the following ways:
- Create a GitHub Issue
- Create a GitHub Discussion
We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines.
clerk-solidjs follows good practices of security, but 100% security cannot be assured.
clerk-solidjs 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.
This project is licensed under the MIT license.
See LICENSE for more information.