Clerk is the easiest way to add authentication and user management to your Astro application. Add sign up, sign in, and profile management to your Astro application in minutes.
- Astro 3.2 or later
- Node.js
>=18.17.0or later
Add @clerk/astro as a dependency
With npm
npm install @clerk/astroWith yarn
yarn add @clerk/astroWith pnpm
pnpm add @clerk/astroTo build the package locally with the TypeScript compiler, run:
npm run buildTo build the package in watch mode, run the following:
npm run devPUBLIC_CLERK_PUBLISHABLE_KEY=pk_(test|live)_xxxxxxx
CLERK_SECRET_KEY=sk_(test|live)_xxxxxxx
PUBLIC_CLERK_SIGN_IN_URL=/sign-in # update this if sign in page exists on another path
PUBLIC_CLERK_SIGN_UP_URL=/sign-up # update this if sign up page exists on another path/// <reference types="astro/client" />
/// <reference types="@clerk/astro/env" />Follow the instructions in our documentation.
Example configuration file
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
import clerk from '@clerk/astro';
export default defineConfig({
integrations: [clerk()],
adapter: node({ mode: 'standalone' }),
output: 'server',
});This step is required in order to use SSR or any control component. Create a middleware.ts file inside the src/ directory.
import { clerkMiddleware } from '@clerk/astro/server';
export const onRequest = clerkMiddleware();---
import { SignedIn, SignedOut, UserButton, SignInButton } from "@clerk/astro/components";
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
</head>
<body>
<header>
<h1>{title}</h1>
<nav>
<SignedOut>
<SignInButton mode="modal" />
</SignedOut>
<SignedIn>
<UserButton />
</SignedIn>
</nav>
</header>
<article>
<slot />
</article>
</body>
</html>For further details and examples, please refer to our Documentation.
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
We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines) .
@clerk/astro follows good practices of security, but 100% security cannot be assured.
@clerk/astro 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.