SDKs overview

Clerk provides Software Development Kits (SDKs) and libraries designed to integrate user authentication and management into web and mobile applications. The SDKs abstract the complexities of identity management, offering both pre-built user interface components and backend helper functions. This approach aims to reduce the development time required for implementing features such as user sign-in, sign-up, user profiles, and organization management. The ecosystem primarily supports JavaScript-based frontend frameworks, with complementary libraries available for various backend environments.

Clerk's strategy emphasizes a React-first design philosophy, providing a comprehensive suite of components for applications built with Next.js, React, and Remix. These frontend SDKs typically include components for common authentication flows and user interface elements, such as sign-in forms, user profile pages, and organization switchers. For backend operations, Clerk offers libraries that facilitate secure token verification, user data retrieval, and API interactions across multiple programming languages, including Node.js, Go, Ruby, and Python. This dual approach ensures that developers can manage both the client-side user experience and server-side security aspects of authentication within their applications. For a broader understanding of identity management systems, the OAuth 2.0 specification outlines common authorization frameworks that many services, including Clerk, build upon.

Official SDKs by language

Clerk maintains official SDKs for a range of frontend frameworks and backend languages, designed to provide comprehensive support for integrating its authentication services. The official SDKs are regularly updated and supported directly by Clerk, ensuring compatibility with the latest features and security standards. These SDKs typically offer a structured way to interact with Clerk's APIs, handle authentication tokens, and manage user sessions.

Frontend SDKs

Clerk's frontend SDKs are primarily designed for JavaScript-based environments, offering pre-built UI components and hooks to streamline the integration of authentication flows. These SDKs allow developers to quickly add sign-in, sign-up, user profiles, and organization management interfaces with minimal custom coding.

  • Next.js: The @clerk/nextjs package provides a dedicated integration for Next.js applications, leveraging React Server Components and client-side rendering where appropriate. It includes components like , , and .
  • React: The @clerk/react package offers core React hooks and components for applications not using Next.js, providing the building blocks for custom authentication UIs.
  • Remix: The @clerk/remix package offers specific utilities and components tailored for the Remix framework, integrating with its routing and data loading conventions.
  • Expo: The @clerk/expo package extends Clerk's capabilities to mobile applications built with Expo, providing authentication flows compatible with React Native environments.
  • Vue: The @clerk/vue package provides a set of composables and components for Vue.js applications, enabling similar authentication integration as its React counterparts.
  • Astro: The @clerk/astro package offers an integration for Astro projects, allowing developers to incorporate Clerk's authentication services within static and dynamic Astro sites.

Backend SDKs

Clerk's backend SDKs are designed to facilitate server-side operations, such as verifying session tokens, accessing user data, and managing Clerk resources directly from your application's backend. These libraries ensure secure communication with Clerk's APIs and provide utility functions for common authentication-related tasks.

  • Node.js: The @clerk/backend package offers methods for verifying session tokens, retrieving user information, and interacting with Clerk's API from Node.js environments.
  • Go: The clerk/clerk-sdk-go package provides Go bindings for Clerk's API, enabling developers to perform server-side authentication checks and user management in Go applications.
  • Ruby: The clerk/clerk-sdk-ruby gem offers a Ruby interface for interacting with Clerk's backend services, supporting session verification and user data access.
  • Python: The clerk/clerk-sdk-python library provides Python developers with tools to integrate Clerk's authentication into their backend applications, including token validation and user management.

The table below summarizes the official SDKs, their corresponding packages, and typical installation commands:

Language/Framework Package Name Install Command Maturity
Next.js @clerk/nextjs npm install @clerk/nextjs or yarn add @clerk/nextjs Stable
React @clerk/react npm install @clerk/react or yarn add @clerk/react Stable
Remix @clerk/remix npm install @clerk/remix or yarn add @clerk/remix Stable
Expo @clerk/expo npm install @clerk/expo or yarn add @clerk/expo Stable
Vue @clerk/vue npm install @clerk/vue or yarn add @clerk/vue Stable
Astro @clerk/astro npm install @clerk/astro or yarn add @clerk/astro Stable
Node.js @clerk/backend npm install @clerk/backend or yarn add @clerk/backend Stable
Go clerk/clerk-sdk-go go get github.com/clerkinc/clerk-sdk-go Stable
Ruby clerk/clerk-sdk-ruby gem install clerk-sdk-ruby Stable
Python clerk/clerk-sdk-python pip install clerk-sdk-python Stable

Installation

Installation of Clerk SDKs typically involves using a package manager relevant to the programming language or framework being used. For JavaScript and its frameworks (Next.js, React, Remix, Expo, Vue, Astro), npm or yarn are the standard tools. For Go, go get is used, while Ruby relies on gem install, and Python uses pip install. Each SDK's documentation provides specific instructions for setup, including environmental variable configuration for API keys and domain settings.

Example: Next.js Installation

For a Next.js application, the installation process begins with adding the @clerk/nextjs package:

npm install @clerk/nextjs
# or
yarn add @clerk/nextjs

After installation, environment variables for Clerk's Publishable Key and Secret Key need to be configured, typically in a .env.local file in the project root. These keys are obtained from the Clerk Dashboard and are essential for the SDK to communicate with Clerk's services. The Clerk Next.js installation guide provides detailed steps.

Quickstart example

To illustrate the basic integration of Clerk, here's a quickstart example for a Next.js application. This example demonstrates how to wrap your application with the ClerkProvider and use a pre-built UI component like SignIn.

1. Configure Environment Variables

Create a .env.local file in your project root and add your Clerk API keys:

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_YOUR_PUBLISHABLE_KEY
CLERK_SECRET_KEY=sk_live_YOUR_SECRET_KEY

2. Wrap your Application with ClerkProvider

In your _app.js or layout.js (for Next.js App Router) file, wrap your application with ClerkProvider. This makes Clerk's authentication context available throughout your app.

// src/app/layout.js (Next.js App Router example)
import { ClerkProvider } from '@clerk/nextjs';

export default function RootLayout({ children }) {
  return (
    <ClerkProvider>
      <html>
        <body>{children}</body>
      </html>
    </ClerkProvider>
  );
}

3. Add a Sign-In Page

Create a new page for sign-in, for example, src/app/sign-in/[[...sign-in]]/page.js, and render the SignIn component:

// src/app/sign-in/[[...sign-in]]/page.js
import { SignIn } from '@clerk/nextjs';

export default function Page() {
  return <SignIn />;
}

This minimal setup provides a functional sign-in page with Clerk's pre-built UI. Users can then sign in using various methods configured in your Clerk Dashboard. Further customization and advanced features are available through the SDKs, as detailed in the Clerk Next.js quickstart documentation.

Community libraries

While Clerk provides official SDKs for major frameworks and languages, the community occasionally develops additional libraries or integrations to extend its functionality or adapt it to less common environments. These community-contributed projects can offer solutions for specific use cases not covered by official SDKs or provide alternative approaches to integration.

Community libraries are typically found on platforms like GitHub, npm, or other language-specific package repositories. Their maintenance status, feature set, and security practices can vary. Developers considering community libraries should review the project's documentation, community activity, and open issues to assess suitability and reliability. For example, developers might look for community-driven integrations for frameworks like Svelte or specific backend micro-frameworks not officially supported. The Mozilla Developer Network's HTTP documentation can be a useful reference for understanding the underlying web protocols that both official and community libraries interact with during authentication processes.

Clerk's official documentation and community forums are generally the best resources for discovering and evaluating community contributions. While Clerk aims to provide comprehensive official support, the open-source nature of many web development tools encourages the creation of supplementary libraries by the broader developer community.