2

When I connect heroku postgres database with Auth0 then i am getting below error.

could not connect to postgres db { [error: no pg_hba.conf entry for host "XXXXXXXX", user "XXXXXX", database "XXXXXX", SSL off]
  name: 'error',
  length: 161,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '496',
  routine: 'ClientAuthentication' }
[error] 28000 - undefined

I am using Auth0 so please find below auth0 code with heroku database details and URL.

configuration.config_file = "postgres://username:password@host:port/DB_name"

function login (email, password, callback) {

  var conString = configuration.config_file;
  postgres(conString, function (err, client) {
    if (err) {
      console.log('could not connect to postgres db', err);
      return callback(err);
    }
  });
}
5
  • Welcome to Stackoverflow. Please post the error messages if you get any. Commented Apr 2, 2015 at 9:08
  • Did you give the proper permissions to allow access to your database? The pg_hba.conf file is were the access permissions are seems like the IP of your server is not listed there or does not have proper permissions. Commented Apr 2, 2015 at 10:10
  • @yakiklein Could you please tell me that how to give permission when we access heroku database with auth0 ? Commented Apr 2, 2015 at 10:21
  • take a look at my answer below. Hope it will be helpful for you. Commented Apr 2, 2015 at 10:25
  • @GauravGupta how did you solved this issue? Commented Dec 7, 2016 at 10:25

3 Answers 3

4

Try to add '?ssl=true' to your conString. Heroku requires access via SSL for remote connections. See https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js (under "Remote Connections") for details.

Sign up to request clarification or add additional context in comments.

Comments

2

The code you write here runs in Auth0 (in the cloud). Which means you'll need to use a hostname or IP address Auth0 can connect to.

If you're using a hostname like DBSERVER01 or an IP address like 10.10.5.1 these are only available within your network and auth0 will not be able to reach them.

Make sure you use the public IP address of your network (like 45.19.3.29) or a public facing hostname (like mydb01.mycompany.com).

2 Comments

How to access heroku postgres database on local machine with auth0 ?
According this doc from Heroku: devcenter.heroku.com/articles/…, you shouldn't hardcode the database URL or IP. You're supposed to fetch it via heroku config:get DATABASE_URL -a your-app. However, this is problematic when using auth0's database action scripts as they are sandboxed and don't allow network access. I haven't figured this out yet - has anyone else come up with a solution?
-2

Take a look at this document from ubuntu website. It explains how to install postgres database locally.

After installing postgres you will need to create a user and give it proper authentication.

2 Comments

thanks for this, I want to use heroku database on local with auth0. please see my code.
This answer doesn't address the fact that the OP is using heroku.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.