GuidesTypeScript

Nuxt with Prisma and Better Auth

Create a Nuxt fullstack app with PostgreSQL, Prisma, Better Auth, oRPC, Tailwind CSS, and a generated Better Fullstack project structure.

Updated October 7, 2026nuxtprismabetter-authpostgres

Use this stack when you want a Vue/Nuxt fullstack app with relational data, email and password sign-in, and typed API contracts, all served by one Nuxt server.

npm create better-fullstack@latest my-nuxt-app -- \  --ecosystem typescript \  --frontend nuxt \  --backend self \  --runtime none \  --database postgres \  --orm prisma \  --auth better-auth \  --api orpc \  --css-framework tailwind

What this creates

  • A Nuxt app in apps/web that serves the pages, the Better Auth endpoints, and the oRPC API from the same origin.
  • PostgreSQL through Prisma, with the Better Auth tables already in the schema.
  • Better Auth with email and password sign-in, a login page, and a protected dashboard.
  • oRPC procedures with TanStack Query helpers for Vue.
  • Tailwind CSS and Nuxt UI.
  • A reproducible bts.jsonc stack configuration.

Generated shape

txt
my-nuxt-app/
  bts.jsonc
  apps/web/
    .env
    nuxt.config.ts
    app/
      pages/            # index.vue, login.vue, dashboard.vue
      components/       # SignInForm.vue, SignUpForm.vue, UserMenu.vue
      middleware/auth.ts
      plugins/          # auth-client.ts, orpc.ts, vue-query.ts
    server/api/
      auth/[...all].ts  # Better Auth handler
      rpc/[...rest].ts  # oRPC handler and OpenAPI reference
  packages/
    api/src/            # context.ts, index.ts, routers/index.ts
    auth/src/index.ts   # betterAuth() with the Prisma adapter
    db/
      prisma.config.ts
      prisma/schema/    # schema.prisma, auth.prisma
    env/src/            # server.ts, web.ts

The Nuxt server routes are thin. server/api/auth/[...all].ts passes each request to auth.handler from packages/auth, and server/api/rpc/[...rest].ts runs the router from packages/api. The oRPC context reads the Better Auth session from the request cookies, so procedures can check the signed-in user.

Routes

RoutePurpose
/loginSign-in and sign-up forms.
/dashboardProtected page that calls privateData. The auth middleware sends signed-out users to /login.
/api/auth/*Better Auth endpoints, such as sign-up/email, sign-in/email, get-session, and sign-out.
/api/rpc/healthCheckPublic oRPC procedure that returns "OK".
/api/rpc/privateDataProtected oRPC procedure. It returns 401 UNAUTHORIZED without a session cookie.
/api/rpc/api-referenceOpenAPI reference for the router.

The auth client and the oRPC client use the page's own origin, so the app needs no public server URL.

Environment

The generator writes apps/web/.env:

VariablePurpose
DATABASE_URLPostgreSQL connection string used by Prisma and the app.
BETTER_AUTH_SECRETGenerated random secret, at least 32 characters.
BETTER_AUTH_URLPublic URL of the app, http://localhost:3001 locally.
CORS_ORIGINOrigin Better Auth trusts for sign-in requests, http://localhost:3001 locally.

Run it locally

Point DATABASE_URL at your PostgreSQL database. From the project root, create the first migration and start the dev server on port 3001:

npm run db:migratenpm run dev

db:migrate runs prisma migrate dev, which asks for a migration name and writes it to packages/db/prisma/migrations. Open http://localhost:3001/login to create an account.

To run the production build, build it and start the Nitro server from apps/web. Nuxt does not load .env in production, so pass it explicitly and keep the port that BETTER_AUTH_URL and CORS_ORIGIN name:

npm run build
bash
cd apps/web
PORT=3001 node --env-file=.env .output/server/index.mjs

Add a model and a procedure

Add product models to packages/db/prisma/schema/schema.prisma and leave auth.prisma to Better Auth. Reference users by identifier:

prisma
model Workspace {
  id        String   @id @default(cuid())
  name      String
  ownerId   String
  createdAt DateTime @default(now())

  @@index([ownerId])
}

Then add a procedure to appRouter in packages/api/src/routers/index.ts. protectedProcedure rejects requests without a session, and context.session.user holds the signed-in user:

ts
createWorkspace: protectedProcedure
  .input(z.object({ name: z.string().min(2) }))
  .handler(({ input, context }) => {
    return prisma.workspace.create({
      data: { name: input.name, ownerId: context.session.user.id },
    });
  }),

Import z from zod and the Prisma client from the db workspace package. After changing the schema, create a migration and then regenerate Prisma Client. In Prisma 7, migrate dev no longer generates the client, so prisma.workspace does not exist until db:generate runs:

npm run db:migratenpm run db:generate

Keep authorization checks in procedures; the auth middleware only improves navigation.

Compatibility notes

Nuxt uses oRPC in Better Fullstack for typed contracts. The CLI rejects tRPC, ts-rest, and garph with Nuxt because they require a React-based frontend, so this guide uses --api orpc.

--backend self with --runtime none is the Nuxt fullstack choice. If you want a separately deployed API server, use a backend option such as Hono in a stack that supports that pairing.

When to choose it

Choose Nuxt when your team prefers Vue, wants server-capable routing, and needs a fullstack app shape rather than a separate frontend and API server.

Deployment notes

Set DATABASE_URL, BETTER_AUTH_SECRET, BETTER_AUTH_URL, and CORS_ORIGIN in the deployment environment. BETTER_AUTH_URL and CORS_ORIGIN must be the deployed origin. Apply migrations with prisma migrate deploy before starting code that depends on new schema.

For serverless platforms, review how your Prisma client is generated and how database connections are pooled. Managed PostgreSQL providers often document the safest connection string for serverless runtimes.

Troubleshooting

  • If sign-in returns 403 with INVALID_ORIGIN, set CORS_ORIGIN to the exact origin in the browser address bar, including the port.
  • If the production server listens on port 3000, set PORT. Nitro ignores the dev server port in nuxt.config.ts.
  • If Prisma Client types are stale, run npm run db:generate after changing the schema.
  • If migrations point at the wrong database, check DATABASE_URL in apps/web/.env. Prisma reads that file through packages/db/prisma.config.ts.

Comparison notes

Use this stack when Vue and Nuxt conventions are the main priority. Choose Next.js with Drizzle and Better Auth for a React-first stack, or SvelteKit with Hono and Drizzle when you want a separate Hono backend.

Next steps

GitHub Sponsors