---
title: "Auth for AI startups: ship fast, grow later"
description: "Open source auth for TypeScript AI startups: scaffold with create-theauth-app, use Next.js or Hono on edge runtimes, then add SSO and SCIM later."
canonical: https://theauth.dev/use-cases/ai-startups/
lastmod: 2026-10-31
---

Use case

# Auth for AI startups

Sign-in on day one, agent identity when your product starts calling tools, and enterprise features when the first large customer asks, all from one MIT licensed library you can read.

[Read the quickstart](https://docs.theauth.dev/quickstart) [Jump to the steps](https://theauth.dev/use-cases/ai-startups/#step-1)

The problem

## You need auth now, and a different auth later.

Early on, auth should cost an afternoon, not a sprint. A few weeks later your product has agents calling tools, and a user table is not enough. Later still, a company asks for SSO.

Switching auth providers at each stage means migrating users three times. The alternative is a library whose scope grows with you, that runs on the runtime you already deploy to, and whose licensing does not change as your user count does.

What an early team wants

- **A working app quickly.**Sign-in and sign-up routes you do not write.
- **Your stack.**Next.js, Hono, or whatever you deploy on, including edge runtimes.
- **No surprise bill.**Licensing that does not scale with users.
- **Room to grow.**Agents, organizations, SSO and SCIM without a migration.

The theAuth path

## Scaffold, deploy anywhere, add features as needed.

theAuth runs as a library inside your own app, mounted through a framework adapter, with your own database behind it (Postgres, MySQL, SQLite or Cloudflare D1). You run the whole stack in your infrastructure, and identities stay in your database.

Step by step

## From an empty folder to a running app.

Scaffold first, then add the pieces your product needs.

### Scaffold the app

Pick `next-saas` for a Next.js App Router app with Drizzle and prebuilt sign-in components, or `hono-mcp` for a Hono server that also acts as an MCP authorization server. The database driver is `better-sqlite3` by default, or `pg` for Postgres.

terminal

```js
npx @glinr/create-theauth-app
cd my-theauth-app
pnpm install
cp .env.example .env   # then set THEAUTH_SECRET
pnpm db:push
pnpm dev
```

### Create the instance

This is the core. Pick the plugins your sign-in needs. Postgres here, SQLite works the same way for local development.

lib/auth.ts

```ts
import { createTheAuth } from "@glinr/theauth";
import { emailPassword, passkey } from "@glinr/theauth/auth";

export const auth = await createTheAuth({
  database: { provider: "postgres", url: process.env.DATABASE_URL },
  plugins: [emailPassword(), passkey()],
});
```

### Mount it in Next.js

A catch-all App Router route hands every auth path to the adapter. The default base path is `/api/theauth`, so pass `basePath` if you want a different one.

The adapter packages are `@glinr/theauth-nextjs` and `@glinr/theauth-hono`.

app/api/theauth/[...theauth]/route.ts

```ts
import { theAuthNextjs } from "@glinr/theauth-nextjs";
import { auth } from "@/lib/auth";

const handlers = theAuthNextjs(auth);

export const GET = handlers.GET;
export const POST = handlers.POST;
export const PATCH = handlers.PATCH;
export const DELETE = handlers.DELETE;
export const OPTIONS = handlers.OPTIONS;
```

### Or run it on Hono at the edge

The same instance mounts in a Hono app, which uses web-standard Request and Response.

src/index.ts

```ts
import { Hono } from "hono";
import { theAuthHono } from "@glinr/theauth-hono";
import { auth } from "./auth";

const app = new Hono();
app.route("/api/auth", theAuthHono(auth));

export default app;
```

### Give your first agent an identity

When your product starts calling tools, add an agent with scoped permissions. See [identity and permissions for AI agents](https://theauth.dev/use-cases/ai-agents/) for delegation, approvals and budgets.

agent.ts

```ts
const agent = await auth.agent.create({
  ownerId: "user-123",
  name: "github-reader",
  type: "autonomous",
  permissions: [{ resource: "mcp:github:*", actions: ["read"] }],
});
```

Checked against the package source and the scaffolder's README for @glinr/theauth 0.5.0 and @glinr/create-theauth-app 0.2.0 on 2026-10-06. The scaffolder's README also lists npm create theauth-app@latest and bunx @glinr/create-theauth-app as equivalents. Not every plugin runs on every runtime, so check the [adapters docs](https://docs.theauth.dev/adapters) before you commit to one.

Pitfalls

## Early-stage mistakes worth avoiding.

- **A placeholder secret in production.**Templates use `.env.example` with an empty `THEAUTH_SECRET`. Set a long random value and keep it out of git.
- **Local SQLite in a serverless deploy.**A file database does not persist on most serverless hosts. Use Postgres, MySQL or Cloudflare D1 there.
- **Mounting the adapter at a path you did not configure.**The Next.js adapter strips its `basePath`, which defaults to `/api/theauth`. Pass the real path if you mount elsewhere.
- **Adding agents without an owner.**Every agent needs an `ownerId`. Decide who owns an agent your product creates on a user's behalf before you ship it.
- **Planning a later migration.**SSO and SCIM are modules of the same library. Adopt organizations early and the enterprise step is configuration, not a user migration.

## Keep reading

- [Auth for B2B SaaS with organizations](https://theauth.dev/use-cases/saas/)
- [Identity and permissions for AI agents](https://theauth.dev/use-cases/ai-agents/)
- [SDKs and adapters on the homepage](https://theauth.dev/#sdks)
- [Quickstart](https://docs.theauth.dev/quickstart)
- [Adapters](https://docs.theauth.dev/adapters)
- [Migrate from Better Auth](https://docs.theauth.dev/migrate/from-better-auth)
