Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unhandled rejection SequelizeConnectionError: password authentication failed for user "ankitj"

This happens even when the DB user specified in .env file is different. For the record "ankitj" is also the username of my system. I don't understand why this is happening.

Here's the error:

Unhandled rejection SequelizeConnectionError: password authentication failed for user "ankitj"
    at connection.connect.err (/home/ankitj/Desktop/skillbee/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:128:24)
    at Connection.connectingErrorHandler (/home/ankitj/Desktop/skillbee/node_modules/pg/lib/client.js:140:14)
    at Connection.emit (events.js:160:13)
    at Socket.<anonymous> (/home/ankitj/Desktop/skillbee/node_modules/pg/lib/connection.js:124:12)
    at Socket.emit (events.js:160:13)
    at addChunk (_stream_readable.js:269:12)
    at readableAddChunk (_stream_readable.js:256:11)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onread (net.js:599:20)
like image 621
ankitjena Avatar asked Dec 11 '18 08:12

ankitjena


2 Answers

I'm assuming that you're getting this error using Sequelize with Node.js. I ran into the same error when I had the following:

const sequelize = new Sequelize(
  process.env.DATABASE,
  process.env.DATABASE_USER,
  process.env.DATABASE_PASSWORD,
  {
    dialect: 'postgres',
  }
)

I was able to solve the issue by replacing it with a connection ur:

const sequelize = new Sequelize("postgres://postgres:postgres@localhost/gql", {
  dialect: 'postgres'
  // anything else you want to pass
})

where gql is the name of DATABASE in my .env file.

The user "ankitj" executes the command to run the Node script, so the script is trying to connect as that user. I first tried to solve this on the Postgres end by adding a user and granting permissions, but was unable to get that to work--I'd be interested in seeing that solution--but specifying a connection url worked for me.

like image 125
crash springfield Avatar answered Sep 18 '22 20:09

crash springfield


I had the same issue when I was using the default password for the PostgreSQL. Try to change it from the command line as follows.

  1. psql
  2. \password

Then Enter a new password and update your .env files and that should Work.

like image 33
Yonatan Dawit Avatar answered Sep 20 '22 20:09

Yonatan Dawit