Introduction
Better IAM is an embeddable TypeScript platform for authentication, identity provisioning, and access management, running in your app on your own database.
Better IAM gives an application the identity layer that is usually bought as a hosted service: multi-tenant organizations, sign-in with every modern method, fine-grained authorization, governance, and enterprise federation. It is a library, not a SaaS. It runs in your process, stores its data in your PostgreSQL, SQLite, or libSQL database, and exposes a typed API to your server and browser code.
You create one instance with betterIam(), giving it a database, a deployment secret, and the URL it is served
from, and import that instance wherever your server code needs identity or authorization:
import { betterIam } from 'better-iam';
import { sqliteAdapter } from 'better-iam/adapter-sqlite';
export const iam = betterIam({
database: sqliteAdapter({ filename: './iam.db' }),
secret: process.env.BETTER_IAM_SECRET!,
baseURL: 'https://identity.example.com',
});Why it exists
Most business software eventually needs the same identity features: customers are organizations rather than individuals, each organization wants its own roles and its own single sign-on, security teams ask who can do what and who changed it, and enterprise buyers expect SCIM provisioning, MFA policies, and an audit trail. Teams usually assemble this from several services: a hosted sign-in provider, a separate authorization service, and later a governance or provisioning tool. That works, but it has costs:
- Your identity data lives somewhere else. People, sessions, and roles sit in a vendor's database, so every permission check is a network call, and keeping that data consistent with your own records is your problem.
- Authorization is disconnected from your data. Deciding "may Alice approve this invoice?" needs the invoice's owner and amount, which the external service does not have.
- Each service has its own model. Tenants, roles, and audit logs are defined three times and reconciled by hand.
Better IAM takes the other approach: it is a library that runs inside your application and stores everything in your database, in the same transactions as your own writes. One model, one authorization engine, and one tamper-evident cover sign-in, access decisions, governance, and federation, all behind a single typed API.
What it covers
Tenants and organizations
Tenant trees with isolated identity directories, invitations, sign-in aliases, and platform root administration.
Authentication
Passwords, passkeys, magic links, email and SMS codes, TOTP, trusted devices, and per-tenant sign-in policies.
Authorization
Roles, versioned JSON policies with conditions and variables, relationships (ReBAC), boundaries, and reverse queries.
Privileged access
Just-in-time elevation with approvals, access packages, temporary bindings, and configuration as code.
Governance
Access reviews, certification campaigns, separation of duties, role mining, invariants, change previews, privacy and consent, lifecycle workflows, compliance evidence, and an app catalog.
Security services
Tenant keys, a secrets vault, tokenization, a private CA, SSH certificates, device posture, and identity threat detection.
Federation
OAuth/OIDC sign-in and provider, SAML SSO, SCIM in and out, Shared Signals (CAEP/RISC) both ways, verifiable credentials, and an LDAP gateway.
Audit and events
A tamper-evident, hash-chained audit log with webhooks, subscribers, metrics, and spans.
Every framework
A typed client plus Next.js, React, Vue, Nuxt, SvelteKit, React Router, NestJS, Express, Hono, and Fastify integrations.
How it fits together
Every operation, whether it comes from a browser, a server action, the CLI, or a SCIM connector, runs through the same pipeline:
- Resolve the . A session cookie, bearer token, API key, or assumed role becomes a : who is calling, how they signed in, and whether they used MFA.
- Authorize. The principal's , , and in that tenant decide whether the action is allowed.
- Apply the change in one transaction in your database, so a failure leaves nothing half done.
- Record it. A hash-chained audit event is appended in the same transaction and then fans out to , in-process subscribers, and metrics.
Because every API call takes this one path, no API call bypasses authorization or the audit log, and an administrator using the console is held to the same rules as your own API calls. Deployment operations that take no credential (migrations, root bootstrap, scheduled jobs) run from your server or the CLI, not over the API.
Who makes it
Better IAM is created and maintained by Sean Filimon. Every package is open source under the Apache License 2.0.
How these docs are organized
| Section | What it covers | Start with |
|---|---|---|
| Get Started | What Better IAM is, how it compares, installing it, and a first working setup | Installation, Quickstart |
| Concepts | The architecture, tenants and identities, resources, the API surface, events, errors, and extensions | Architecture overview |
| Authentication | Sign-in methods, sessions, MFA, passkeys, API keys, tokens, and per-tenant sign-in policies | Authentication |
| Authorization | Roles, policies, conditions, relationships, reverse queries, and data filtering | Authorization |
| Databases | The PostgreSQL, SQLite, and libSQL adapters, migrations, and the schema | Databases |
| Integrations | The typed client and every framework integration | Integrations |
| Features | Optional modules you turn on with options: privileged access, governance, secrets and keys, AI agents, billing, and more | Features |
| Federation | OAuth/OIDC, SAML, SCIM, Shared Signals, verifiable credentials, and LDAP | Federation |
| Guides | Task-oriented walkthroughs, migration from other providers, upgrade notes, and a recipes cookbook | Guides |
| Operations | Deployment, secrets, scheduled jobs, observability, and security | Operations |
| AI Resources | Ways to give coding agents these docs: MCP, llms.txt, agent skills, and prompts | Use the docs with AI |
| Reference | Generated reference for every API method, option, error code, CLI command, and export | Reference |
Docs for AI
These docs are written to be read by coding agents as well as people: every page is available as Markdown, the
site publishes /llms.txt and /llms-full.txt, and a read-only MCP server lets an assistant search pages and look
up API methods, exports, and error codes while it works. See Use the docs with AI to connect Claude
Code, Cursor, or VS Code.
Where to go next
Install the package, connect a database, and mount the handler in your framework.
QuickstartBootstrap the root, create an organization, and make your first authorization check.
ComparisonHow Better IAM differs from hosted providers, authentication libraries, and authorization services.
ConceptsHow tenants, identities, resources, and the request pipeline fit together.
GuidesBuild a B2B SaaS, protect an API, add enterprise SSO, and migrate from another provider.
Policy playgroundEvaluate policy documents in your browser with the real policy engine.
Better IAM is created by Sean Filimon
Last updated