Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub


Chat on Discord Clerk documentation Follow on Twitter

Changelog · Report a Bug · Request a Feature · Ask a Question


Clerk is the easiest way to add authentication and user management to your Gatsby application. Add sign up, sign in, and profile management to your application in minutes.

Getting Started


  • Gatsby v5+
  • Node.js v18+


npm install gatsby-plugin-clerk


Make sure the following environment variables are set in a .env file:


You can get these from the API Keys screen in your Clerk dashboard.

To initialize Clerk with your Gatsby application, simply register the plugin in your gatsby-config.ts/gatsby-config.js file. Also, use dotenv to access environment variables.

// gatsby-config.ts
import type { GatsbyConfig } from 'gatsby';

  path: `.env.${process.env.NODE_ENV}`,

const config: GatsbyConfig = {
  // ...the rest of your config object
  plugins: ['gatsby-plugin-clerk'],

export default config;


After those changes are made, you can use Clerk components in your pages.

For example, in src/pages/index.tsx:

import { SignedIn, SignedOut, SignInButton, UserButton } from 'gatsby-plugin-clerk';

const IndexPage = () => {
  return (
      <h1>Hello Clerk!</h1>
        <UserButton />
        <SignInButton mode='modal' />

export default IndexPage;

Server-Side Rendering (SSR)

Using withServerAuth from 'gatsby-plugin-clerk/ssr'. Example file /pages/ssr.tsx:

import * as React from 'react';
import { GetServerData } from 'gatsby';
import { withServerAuth } from 'gatsby-plugin-clerk/ssr';

export const getServerData: GetServerData<any> = withServerAuth(
  async props => {
    return { props: { data: '1', auth: props.auth } };
  { loadUser: true },

function SSRPage({ serverData }: any) {
  return (
      <h1>SSR Page with Clerk</h1>
      <pre>{JSON.stringify(serverData, null, 2)}</pre>

export default SSRPage;

Server API routes

Importing 'gatsby-plugin-clerk/api' gives access to all the exports coming from @clerk/sdk-node. Example file /api/hello.ts:

import { clerkClient, withAuth } from 'gatsby-plugin-clerk/api';

const handler = withAuth(async (req, res) => {
  const users = await clerkClient.users.getUserList();
  res.send({ title: `We have ${users.length} users`, auth: req.auth });

export default handler;

For further details and examples, please refer to our Documentation.


To build the package locally with the TypeScript compiler, run:

npm run build

To build the package in watch mode, run the following:

npm run dev


You can get in touch with us in any of the following ways:


We’re open to all community contributions! If you’d like to contribute in any way, please read our contribution guidelines.


gatsby-plugin-clerk follows good practices of security, but 100% security cannot be assured.

gatsby-plugin-clerk 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.

© 2023 Gatsby, Inc.