Polar

Polar integration for Better Auth.

Installation

Simple Polar configuration.

code-editor
pnpm dlx shadcn@latest add @auth-cn/polar

Add Polar sh

code-editor

lib/auth.ts

import { betterAuth } from "better-auth";
// Import the polar plugin
import { polarPlugin } from "@/lib/polar";

const auth = betterAuth({
  // Better Auth config...
  // Add the polar plugin
  plugins: [polarPlugin],
});

import and add the polar plugin to Better Auth.

code-editor

lib/auth-client.ts

import { createAuthClient } from "better-auth/react";
// Import the polar client
import { polarClient } from "@polar-sh/better-auth";

// This is all that is needed
// All Polar plugins, etc. should be attached to the server-side BetterAuth config
export const authClient = createAuthClient({
  // auth client config...
  plugins: [polarClient()],
});

Add the polar client to the Better Auth Client.