node.jspostgresqlprisma

User was denied access on the postgresql database (nodejs, prisma)


I have these lines of code that try to use prisma with postgresql:

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function create()
{
    await prisma.user.create({

        data: {

            id: 0,
            email: "smth@smth.com",
            name: "john"
        }
    })
}

create()
    .catch(e => {

        console.log(e.message);
    })
    .finally(async () => {

        await prisma.$disconnect()
    })

And this thing then types this: Invalid prisma.user.create() invocation in /home/Mindw1n/Studying/NodeJsProjects/first/app.js:6:23

User postgres was denied access on the database first.public Here's my schema.prisma:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres:pass@localhost:5432/first"
}

model User {

  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}

What do I do to connect node.js with prisma to postgresql?


Solution

  • I had a similar issue, the problem is usually from pg_hba.conf Open it, and change 'peer' and 'ident' to md5

    it fixed my problem