Error: self-signed certificate in certificate chain

Hi,

I am getting a 500 runtime error on my webapp made with Nextjs (v14.2.16) + drizzle-kit & drizzle-orm + @vercel/postgres running on Supabase DB.

Here’s the stack trace:

Unexpected error: Error: self-signed certificate in certificate chain
    at /var/task/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /var/task/.next/server/chunks/749.js:7:34868
    at async c (/var/task/.next/server/app/api/survey/[slug]/route.js:1:899)
    at async /var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37010
    at async eC.execute (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:27552)
    at async eC.handle (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:38344)
    at async es (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:16:25262)
    at async en.responseCache.get.routeKind (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:1026)
    at async r6.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:508) {
  code: 'SELF_SIGNED_CERT_IN_CHAIN'

<!-- Current versus Expected behavior -->

I’ve tried to use this as per recommendation from cursor but no success:

const pool = new Pool({
	connectionString: process.env.POSTGRES_URL,
	ssl: {
		rejectUnauthorized: false, // This allows self-signed certificates
	},
});

I’ve also tried the fix as per discussion here Error: self signed certificate in certificate chain · drizzle-team/drizzle-orm · Discussion #881 · GitHub

This is my drizzle.config.js:

import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';

if (!process.env.POSTGRES_URL) {
	throw new Error('POSTGRES_URL environment variable is required');
}

if (!process.env.DATABASE_CA) {
	throw new Error('DATABASE_CA environment variable is required');
}

export default defineConfig({
	out: './db/migrations',
	schema: './db/schema.ts',
	dialect: 'postgresql',
	dbCredentials: {
		// url: `${process.env.POSTGRES_URL!}?sslmode=no-verify`,
		url: process.env.POSTGRES_URL!,
		ssl: { ca: process.env.DATABASE_CA },
	},
});

and this is how I connect to PostgreSQL:

// Create a PostgreSQL pool using connection string from environment variables
const pool = new Pool({
	connectionString: process.env.POSTGRES_URL,
	ssl: {
		rejectUnauthorized: false, // This allows self-signed certificates
	},
});
const db = drizzle(pool, { schema });

Hello,

//drizzle.config.ts
dbCredentials: {
        // using url doesn't work because it seems to override the ssl config
        // url: process.env.DATABASE_URL!,
        host: process.env.DATABASE_HOST!,
        port: parseInt(process.env.DATABASE_PORT!),
        user: process.env.DATABASE_USER!,
        password: process.env.DATABASE_PASSWORD!,
        database: process.env.DATABASE_NAME!,
        ssl: { ca: process.env.DATABASE_CA! },
    },

make sure you’re not using url, and set up the individual connection url components instead

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.