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:
but the runtime query is targeting:
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
- Create or use a PostgreSQL database with a schema different from
public.
For example:
- Configure Typebot with a custom PostgreSQL schema:
DATABASE_URL=postgresql://postgres:password@postgres.example.com:5432/typepot?schema=chatbot
-
Start Typebot v3.17.2 using Docker or Docker Compose.
-
Confirm that Prisma Migrate correctly detects the custom schema:
Datasource "db": PostgreSQL database "typébot", schema "chatbot"
- Confirm that migrations are successfully detected/applied:
82 migrations found in prisma/migrations
No pending migrations to apply.
-
Attempt to authenticate using an SSO provider.
-
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:
instead of:
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:
and the PostgreSQL schema defined through:
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:
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.
Describe the bug
after upgrading Typebot from
v3.6.xtov3.17.2, SSO authentication stopped working when PostgreSQL is configured with a custom schema through theschemaquery parameter inDATABASE_URL.My database connection string is configured like this:
The Typebot database tables, including
Account,User,Session,VerificationToken, and_prisma_migrations, are located in thechatbotschema.During container startup, Prisma Migrate correctly detects the custom schema:
However, when logging in through an SSO provider, the Prisma Client tries to query the
publicschema instead:The
Accounttable exists at:but the runtime query is targeting:
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.2Deployment: Docker / Docker Compose
Database: PostgreSQL
PostgreSQL database:
typebotPostgreSQL schema:
chatbotAuthentication: SSO
DATABASE_URLcontains?schema=chatbotExample:
Steps to reproduce
public.For example:
Start Typebot
v3.17.2using Docker or Docker Compose.Confirm that Prisma Migrate correctly detects the custom schema:
Attempt to authenticate using an SSO provider.
Authentication fails with:
Expected behavior
Prisma Client runtime queries should use the same PostgreSQL schema configured in
DATABASE_URL.With:
the following Prisma query:
should query:
instead of:
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:
and the PostgreSQL schema defined through:
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:
Although
databaseUrlcontains:the runtime adapter does not appear to apply that schema to Prisma ORM queries.
As a consequence:
This explains why startup/migrations succeed while SSO authentication fails.