Clerk is a developer-first authentication and user management solution. It provides pre-built React components and hooks for sign-in, sign-up, user profile, and organization management. Clerk is designed to be easy to use and customize, and can be dropped into any Astro application.
This quickstart repo contains an example Astro project integrated with Clerk authentication ready to be deployed to Cloudflare pages.
This quickstart contains examples of:
- Using Clerk components for signing in and out.
- Displaying different components depending on whether the user is signed in.
- Protecting routes with
clerkMiddleware
. - Using Tailwind CSS to customize Clerk components.
- Using themes from
@clerk/themes
to customize components. - Accessing user data with
$userStore
- Using environment variable redirects
git clone https://github.com/jeremy-clerk/clerk-astro-cloudflare-quickstart
To run the example locally, you need to:
-
Sign up for a Clerk account at https://clerk.com.
-
Go to the Clerk dashboard and create an application.
-
Rename the wrangler.example.toml example file to
wrangler.toml
-
In
wrangler.toml
, change the value ofPUBLIC_CLERK_PUBLISHABLE_KEY
to be your publishable key from the Clerk Dashboard. -
Rename the .dev.vars.example example file to
.dev.vars
-
In
.dev.vars
change the value ofCLERK_SECRET_KEY
to be your secret key from the Clerk Dashboard -
Run
pnpm install
to install the required dependencies. -
Run
pnpm dev
to launch the development server. -
Go to
http://localhost:4321
in your browser to see the example.
Install Wrangler
pnpm add wrangler --save-dev
Build your project locally
pnpm build
Run the preview script
pnpm preview
Easily deploy to Cloudflare Pages
# Install Wrangerl CLI
pnpm i -g wrangler
# Login into your Cloudflare account
wrangler login
# Run your build command
pnpm run build
# Create new deployment
pnpx wrangler pages deploy ./dist
Once deployed you need to set the CLERK_SECRET_KEY
via the settings for the project via the Cloudflare dashboard.
To learn more about Clerk and Astro, check out the following resources:
Feel free to create a support thread on our Discord. Our support team will be happy to assist you in the #support
channel.
You can discuss ideas, ask questions, and meet others from the community in our Discord.
If you prefer, you can also find support through our Twitter, or you can email us!