简体   繁体   中英

SASL error in postgres connection with node.js

I am having the following error when trying to make a connection to my database:

Conexão estbabelecida com sucesso
Acessar http://localhost:3000
Servidor executando na porta 3000
C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg\lib\sasl.js:24
    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
    ^

Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
    at Object.continueSession (C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg\lib\sasl.js:24:11)
    at Client._handleAuthSASLContinue (C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg\lib\client.js:257:10)
    at Connection.emit (events.js:315:20)
    at C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg\lib\connection.js:114:12
    at Parser.parse (C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg-protocol\dist\parser.js:40:17)
    at Socket.<anonymous> (C:\Users\lopes\Desktop\Javascript\novo-projeto\ExpressEWebpack\node_modules\pg-protocol\dist\index.js:11:42)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
[nodemon] app crashed - waiting for file changes before starting...

Heres my code to connection

require('dotenv').config();
const express = require('express');
const app = express(); 
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize(process.env.DB_URL);

try {
    sequelize.authenticate();
    console.log('Conexão estbabelecida com sucesso')
}catch{
    console.log('Erro ao estabelecer conexão');
}

const session = require('express-session');
const flash = require('connect-flash');

const routes = require('./routes')
const path = require('path');


app.use(express.urlencoded({  extended:true }));

app.use(express.static(path.resolve(__dirname, 'public')));

const sessionOptions = session({
    secret:process.env.cookie_secret,
    store: new (require('connect-pg-simple')(session))(),
    resave: false,
    saveUninitialized: false,
    cookie: {maxAge: 1000 * 60 * 60 * 24 * 7}
});

app.use(sessionOptions);
app.use(flash());

app.set('views', path.resolve(__dirname, 'src', 'views'));
app.set('view engine', 'ejs');

app.use(routes);

app.listen(3000, () => {
    console.log('Acessar http://localhost:3000');
    console.log('Servidor executando na porta 3000');
});

I having this error but my dabatase doenst have a password at all, the fact that i dont have a password could interfere in the connection? In some way,password receives null for having no value? I tried to resolve,seeing what's on sasl.js,but it didn't help much

In your pg_hba.conf file (on Windows the directory is \Program Files\PostgreSQL\13\data ) change IPv4 and IPv6 local connections' method to trust . The scram-sha-256 encryption mechanism expects a password which is why it fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM