Stop renting software.

← All tools · auth

Open source alternatives to Clerk

Clerk starts at $20 (pricing). Here are 3 self-hostable options – free to run on your own server.

better-auth

★ 30.3kMIT
self-host: easy

better-auth/better-auth

supertokens-core

★ 15.3kApache-2.0 (+ separate enterprise/EE license for some dirs)
self-host: easy

supertokens/supertokens-core

logto

★ 14.7kMPL-2.0
self-host: easy

logto-io/logto

Build it yourself with AI

Use OSS auth library; AI can wire it up quickly.

Paste this prompt into Cursor, Claude Code, Codex or any coding agent to build a minimal self-hosted Clerk clone, deployable with Docker on a VPS.

You are a senior full-stack engineer. Build a minimal, self-hosted clone of Clerk (auth) that I can run on my own VPS. Keep it small, production-sane, and easy to maintain.

## Goal
Replace my paid Clerk subscription for a single person or small team. MVP only — no billing, no enterprise features.

## Core features (build exactly these)
1. drop-in React sign-in/sign-up components
2. email/password, magic links, OAuth
3. session management with secure cookies
4. organizations with roles
5. user profile page

## Stack
- Next.js (App Router, TypeScript) + Tailwind + shadcn/ui
- PostgreSQL with Drizzle ORM (migrations checked in)
- Auth: Better Auth (email + password, optional GitHub OAuth); every query scoped to the signed-in user/workspace
- Background jobs (if needed): pg-boss on the same Postgres
- File storage (if needed): S3-compatible (MinIO container)

## Data model (start here, extend only if required)
User, Session, Organization, Membership, OAuthAccount
Use UUID primary keys, createdAt/updatedAt on every table, and foreign keys with sensible ON DELETE behavior.

## Deliverables
1. Working app with the features above and a clean, minimal UI
2. docker-compose.yml with app, postgres, minio and Caddy (automatic HTTPS) — `docker compose up -d` must be all I run
3. .env.example documenting every variable; no secrets in code
4. Seed script with demo data
5. README: local dev, deploy on a fresh Ubuntu VPS (install Docker, set DNS A record, compose up), backups (pg_dump cron), and updating

## Rules
- Build in small steps; after each feature, run typecheck and the app, and fix errors before moving on
- Validate all input with zod; rate-limit public endpoints
- Write a few Playwright smoke tests for the main flow
- Ask me before adding any dependency beyond the stack above

For reference (study the approach, don't copy code): https://github.com/better-auth/better-auth, https://github.com/supertokens/supertokens-core, https://github.com/logto-io/logto

One self-hosted swap per week

A new SaaS teardown and its open-source replacement, every week. No spam.

We only use your email to send the SelfHostThis newsletter (stored with our email provider Resend, EU). Every email has a one-click unsubscribe link, and you can ask us to delete your data anytime. We use double opt-in. Datenschutz · Privacy policy