npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@temporal.ai/auth-clerk

v1.0.0

Published

Open source, production-ready Clerk authentication integration that saves developers days of setup time

Downloads

5

Readme

@temporal.ai/auth-clerk

Production-ready Clerk authentication integration for React and Express applications. Simplify your authentication workflow with TypeScript-first, zero-configuration setup.

Features

React Hooks - Authenticated API calls with automatic token management
Express Middleware - JWT verification and user context
Route Protection - Components for protecting React routes
TypeScript First - Full type safety out of the box
Zero Config - Works with sensible defaults
Production Ready - Error handling, loading states, and optimization

Quick Start

Installation

npm install @temporal.ai/auth-clerk

React Setup

import { ClerkProvider } from '@clerk/clerk-react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useAuthenticatedApi, ProtectedRoute } from '@temporal.ai/auth-clerk';

function Dashboard() {
  const { useAuthenticatedQuery } = useAuthenticatedApi();
  
  const { data: profile } = useAuthenticatedQuery(['/api/user/profile']);
  
  return <div>Welcome, {profile?.firstName}!</div>;
}

function App() {
  return (
    <ClerkProvider publishableKey={process.env.REACT_APP_CLERK_PUBLISHABLE_KEY}>
      <QueryClientProvider client={new QueryClient()}>
        <ProtectedRoute>
          <Dashboard />
        </ProtectedRoute>
      </QueryClientProvider>
    </ClerkProvider>
  );
}

Express Setup

const express = require('express');
const { requireAuth } = require('@temporal.ai/auth-clerk');

const app = express();

app.get('/api/user/profile', requireAuth(), (req, res) => {
  res.json({ userId: req.userId });
});

API Reference

React Hooks

useAuthenticatedApi(options?)

Hook for making authenticated API calls with automatic token management.

const { useAuthenticatedQuery, useAuthenticatedMutation, authenticatedFetch } = useAuthenticatedApi({
  baseUrl: '/api',
  defaultHeaders: { 'Custom-Header': 'value' }
});

Options:

  • baseUrl?: string - Base URL for API calls
  • defaultHeaders?: Record<string, string> - Default headers for all requests

Returns:

  • useAuthenticatedQuery<T>(queryKey, enabled?, options?) - React Query with auth
  • useAuthenticatedMutation<TData, TVariables>(url, method?, options?) - Mutation with auth
  • authenticatedFetch(url, options?) - Raw fetch with authentication

Components

<ProtectedRoute>

Component that protects routes and requires authentication.

<ProtectedRoute
  fallback={<div>Access denied</div>}
  requireEmailVerified={true}
  customCheck={(user) => user.role === 'admin'}
>
  <Dashboard />
</ProtectedRoute>

Props:

  • children: ReactNode - Content to show when authenticated
  • fallback?: ReactNode - Content to show when access is denied
  • requireEmailVerified?: boolean - Require verified email
  • customCheck?: (user) => boolean - Custom authorization logic

<AuthGate>

Simple gate that shows children only when authenticated.

<AuthGate fallback={<SignInButton />}>
  <UserProfile />
</AuthGate>

Express Middleware

requireAuth(options?)

Middleware to verify Clerk JWT tokens and add user info to request.

app.get('/protected', requireAuth({
  includeUserData: true,
  onAuthError: (error, req, res) => {
    res.status(401).json({ message: 'Custom error handling' });
  }
}), (req, res) => {
  console.log(req.userId, req.clerkUser);
});

Options:

  • includeUserData?: boolean - Fetch full user data from Clerk
  • onAuthError?: (error, req, res) => void - Custom error handler
  • getToken?: (req) => string - Custom token extraction

requireUserInDatabase(getUserFn)

Middleware to ensure user exists in your database.

app.get('/settings', 
  requireAuth(),
  requireUserInDatabase(clerkId => db.getUserByClerkId(clerkId)),
  (req, res) => {
    // req.user is guaranteed to exist
    res.json(req.user);
  }
);

Examples

Full React Example

Check out examples/react-example.tsx for a complete implementation with:

  • Dashboard with user profile
  • Protected routes
  • Landing page with conditional auth
  • Mutation examples

Full Express Example

Check out examples/express-example.js for a complete backend with:

  • User profile endpoints
  • Database integration
  • Custom authentication flows
  • Error handling

TypeScript Support

This package is built with TypeScript and includes full type definitions. All hooks and components are fully typed for the best developer experience.

// Types are automatically inferred
const { data: profile } = useAuthenticatedQuery<UserProfile>(['/api/profile']);
const mutation = useAuthenticatedMutation<UpdateResponse, UpdateRequest>('/api/update');

License

MIT © Temporal AI Technologies

Contributing

Issues and pull requests are welcome! Please visit our GitHub repository.