Convex-Zen Authentication Component

1.13.5 · active · verified Wed Apr 22

Convex-Zen is a production-grade authentication component designed for applications leveraging the Convex backend. Currently at version 1.13.5, it offers a robust, reusable auth solution. The package is actively maintained with frequent releases, typically multiple bug fixes and dependency updates within a month, reflecting ongoing development. Its key differentiator from Convex's 'Better Auth' integration is that Convex-Zen implements native authentication logic directly within Convex component functions, rather than importing an external runtime into app code. It provides framework-specific exports, allowing seamless integration with popular environments like Next.js, Tanstack Start, and Expo, while exposing a consistent and familiar API surface for developers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart illustrates the essential steps to set up Convex-Zen authentication, including defining provider configurations, integrating with Convex's auth bridge, wiring the framework-specific provider (using Tanstack Start as an example), and executing the necessary code generation step.

npm install convex convex-zen @tanstack/react-start

// convex/zen.config.ts
import { defineConvexZen } from 'convex-zen';

export default defineConvexZen({
  authProviders: [{
    domain: process.env.NEXT_PUBLIC_CLERK_ISSUER_URL ?? '', // Example for Clerk or similar OIDC provider
    appId: process.env.NEXT_PUBLIC_CLERK_APP_ID ?? '',
    clientUrl: process.env.NEXT_PUBLIC_CONVEX_URL ?? '',
  }],
  // ... other configuration like roles, permissions
});

// convex/auth.config.ts
import * as auth from 'convex-zen/auth';
export default auth.config;

// app/root.tsx (Example for Tanstack Start application's root layout)
import React from 'react';
import { Outlet } from '@tanstack/react-router';
import { ConvexProviderWithAuth } from 'convex-zen/tanstack-start';
import { ConvexReactClient } from 'convex/react';

const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL ?? '');

export default function Root() {
  return (
    <ConvexProviderWithAuth client={convex}>
      <Outlet />
    </ConvexProviderWithAuth>
  );
}

// After defining configurations and installing packages, run the CLI tool:
npx convex-zen generate

view raw JSON →