Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

Ive read documentation from several pages on SO of this issue, but i havent been able to fix my issue with this particular error.

    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\CNFis\Desktop\WulfDevelopments\ThePantry\node_modules\pg\lib\sasl.js:24:11)
    at Client._handleAuthSASLContinue (C:\Users\CNFis\Desktop\WulfDevelopments\ThePantry\node_modules\pg\lib\client.js:257:10)
    at Connection.emit (events.js:400:28)
    at C:\Users\CNFis\Desktop\WulfDevelopments\ThePantry\node_modules\pg\lib\connection.js:114:12
    at Parser.parse (C:\Users\CNFis\Desktop\WulfDevelopments\ThePantry\node_modules\pg-protocol\dist\parser.js:40:17)
    at Socket.<anonymous> (C:\Users\CNFis\Desktop\WulfDevelopments\ThePantry\node_modules\pg-protocol\dist\index.js:11:42)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)

its as if in my connectDB() function its not recognizing the password to the database. I am trying to run a seeder.js script to seed the database with useful information for testing purposes, and if i run npm run server which is a script that just starts a nodemon server, itll connect to the DB just fine. but when i try to run my script to seed data, i am returning this error.

import { Sequelize } from "sequelize";
import colors from "colors";
import dotenv from "dotenv";

dotenv.config();

const user = "postgres";
const host = "localhost";
const database = "thePantry";
const port = "5432";

const connectDB = async () => {
  const sequelize = new Sequelize(database, user, process.env.DBPASS, {
    host,
    port,
    dialect: "postgres",
    logging: false,
  });
  try {
    await sequelize.authenticate();
    console.log("Connection has been established successfully.".bgGreen.black);
  } catch (error) {
    console.error("Unable to connect to the database:".bgRed.black, error);
  }
};

export default connectDB;

above is my connectDB() file, and again, it works when i run the server normally. but i receive this error only when trying to seed the database. Ill post my seeder script below:

import dotenv from "dotenv";
import colors from "colors";
import users from "./data/users.js";

import User from "./models/userModel.js";

import connectDB from "./config/db.js";

dotenv.config();
console.log(process.env.DBPASS);

connectDB();

const importData = async () => {
  try {
    await User.drop();
    await User.sync();

    await User.bulkCreate(users);

    console.log("Data Imported".green.inverse);
    process.exit();
  } catch (e) {
    console.error(`${e}`.red.inverse);
    process.exit(1);
  }
};

const destroyData = async () => {
  try {
    await User.bulkDestroy();

    console.log("Data Destroyed".red.inverse);
    process.exit();
  } catch (e) {
    console.error(`${e}`.red.inverse);
    process.exit(1);
  }
};

if (process.argv[2] === "-d") {
  destroyData();
} else {
  importData();
}
like image 842
Austin Howard Avatar asked Aug 31 '25 17:08

Austin Howard


1 Answers

Add your .env file in your project, I think your .env file is missing in your project folder. add like this: enter image description here

like image 96
Khadim H. Avatar answered Sep 02 '25 09:09

Khadim H.