如何连接postgres数据库与Auth0
当我连接Heroku postgres数据库与Auth0然后我得到以下错误。
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
我正在使用Auth0,所以请使用heroku数据库详细信息和URLfind下面的auth0代码。
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); } }); }
你在这里写的代码运行在Auth0(在云中)。 这意味着您需要使用Auth0可以连接的主机名或IP地址。
如果您使用的是DBSERVER01
类的主机名或10.10.5.1之类的IP地址,则只能在您的networking中使用这些主机名,而auth0将无法访问它们。
确保你使用你的networking的公共IP地址(如45.19.3.29
)或一个面向公众的主机名(如mydb01.mycompany.com
)。
尝试在您的conString中添加“?ssl = true”。 Heroku需要通过SSL访问远程连接。 有关详细信息,请参阅https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js (位于“远程连接”下)。
从Ubuntu的网站上看看这个文件 。 它解释了如何在本地安装postgres数据库。
安装postgres后,你将需要创build一个用户,并给予适当的身份validation。