Skip to content

PostgreSQL custom schema is ignored by PrismaPg adapter, causing Auth.js SSO failure #2578

Description

@passarela

Describe the bug
after upgrading Typebot from v3.6.x to v3.17.2, SSO authentication stopped working when PostgreSQL is configured with a custom schema through the schema query parameter in DATABASE_URL.

My database connection string is configured like this:

DATABASE_URL=postgresql://postgres:REDACTED@postgres.example.com:5432/typebot?schema=chatbot

The Typebot database tables, including Account, User, Session, VerificationToken, and _prisma_migrations, are located in the chatbot schema.

During container startup, Prisma Migrate correctly detects the custom schema:

Loaded Prisma config from packages/prisma/prisma.config.ts.

Prisma schema loaded from packages/prisma/postgresql/schema.prisma.

Datasource "db": PostgreSQL database "typebot", schema "chatbot" at "postgres.example.com:5432"

82 migrations found in prisma/migrations

No pending migrations to apply.

However, when logging in through an SSO provider, the Prisma Client tries to query the public schema instead:

[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror

[auth][cause]: PrismaClientKnownRequestError:

Invalid `prisma.account.findUnique()` invocation:

The table `public.Account` does not exist in the current database.

The Account table exists at:

chatbot.Account

but the runtime query is targeting:

public.Account

This creates a mismatch between the schema used by Prisma Migrate and the schema used by Prisma Client at runtime.


Environment

  • Typebot version: v3.17.2

  • Deployment: Docker / Docker Compose

  • Database: PostgreSQL

  • PostgreSQL database: typebot

  • PostgreSQL schema: chatbot

  • Authentication: SSO

  • DATABASE_URL contains ?schema=chatbot

Example:

DATABASE_URL=postgresql://postgres:REDACTED@postgres.example.com:5432/typebot?schema=chatbot

Steps to reproduce

  1. Create or use a PostgreSQL database with a schema different from public.

For example:

CREATE SCHEMA chatbot;
  1. Configure Typebot with a custom PostgreSQL schema:
DATABASE_URL=postgresql://postgres:password@postgres.example.com:5432/typepot?schema=chatbot
  1. Start Typebot v3.17.2 using Docker or Docker Compose.

  2. Confirm that Prisma Migrate correctly detects the custom schema:

Datasource "db": PostgreSQL database "typébot", schema "chatbot"
  1. Confirm that migrations are successfully detected/applied:
82 migrations found in prisma/migrations

No pending migrations to apply.
  1. Attempt to authenticate using an SSO provider.

  2. Authentication fails with:

typebot-builder-1  | The table `public.Account` does not exist in the current database.
typebot-builder-1  |     at zr.handleRequestError (/app/node_modules/@prisma/client/runtime/client.js:65:8172)
typebot-builder-1  |     at zr.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/client.js:65:7467)
typebot-builder-1  |     at zr.request (/app/node_modules/@prisma/client/runtime/client.js:65:7174)
typebot-builder-1  |     at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
typebot-builder-1  |     at async a (/app/node_modules/@prisma/client/runtime/client.js:75:5816)
typebot-builder-1  |     at async getUserByAccount (/app/apps/builder/.next/server/chunks/[root-of-the-server]__c1ad5759._.js:579:316713)
typebot-builder-1  |     at async o.<computed> (/app/apps/builder/.next/server/chunks/[root-of-the-server]__c1ad5759._.js:134:93114)
typebot-builder-1  |     at async aM (/app/apps/builder/.next/server/chunks/[root-of-the-server]__c1ad5759._.js:537:38698)
typebot-builder-1  |     at async aY (/app/apps/builder/.next/server/chunks/[root-of-the-server]__c1ad5759._.js:537:50540)
typebot-builder-1  |     at async aJ (/app/apps/builder/.next/server/chunks/[root-of-the-server]__c1ad5759._.js:537:55531)
typebot-builder-1  | [auth][details]: {}


Expected behavior

Prisma Client runtime queries should use the same PostgreSQL schema configured in DATABASE_URL.

With:

DATABASE_URL=postgresql://postgres:password@postgres.example.com:5432/typebot?schema=chatbot

the following Prisma query:

await prisma.account.findUnique(...)

should query:

chatbot.Account

instead of:

public.Account

The schema used by Prisma Client at runtime should be consistent with the schema used by Prisma Migrate.

Suspected cause

The issue appears to be related to the PostgreSQL driver adapter introduced around Typebot v3.16.0.

Before this change, Typebot instantiated Prisma Client directly:

new PrismaClient()

and the PostgreSQL schema defined through:

?schema=chatbot

was correctly honored.

After the introduction of @prisma/adapter-pg, Typebot creates Prisma Client using a PostgreSQL adapter.

The adapter is currently created using only the connection string:

new PrismaPg({
  connectionString: databaseUrl,
});

Although databaseUrl contains:

?schema=chatbot

the runtime adapter does not appear to apply that schema to Prisma ORM queries.

As a consequence:

Prisma Migrate
    ↓
reads schema=chatbot
    ↓
uses chatbot schema

Prisma Client runtime
    ↓
PrismaPg adapter
    ↓
defaults to public schema
    ↓
queries public.Account

This explains why startup/migrations succeed while SSO authentication fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions