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

Viewed 153
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

I looked for some solutions for this one in the stack overflow and many say it would be a dotenv problem, but in my case the application was working normally before without any modification in dotenv, I already tried to import in other ways and the error continues, so I believe that it's a typeORM error.

database config

import { DataSource } from "typeorm"
import { User } from "../entities/User"

export const AppDataSource = new DataSource({
    type: "postgres",
    host: process.env.DATABASE_HOST,
    port: 5432,
    username: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    synchronize: true,
    logging: true,
    entities: [User],
    subscribers: [],
    migrations: [],
})

entity User

import { BeforeInsert, BeforeUpdate, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import bcrypt from 'bcryptjs';

@Entity('users')
export class User {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Column()
    username: string;

    @Column()
    email: string;

    @Column()
    password: string;

    @BeforeInsert()
    @BeforeUpdate()
    hashPassword() {
        this.password = bcrypt.hashSync(this.password, 8);
    }
}

app

import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import 'reflect-metadata';

import userRoutes from './src/routes/UserRoutes';

dotenv.config();

const app = express();

app.use(express.json());
app.use(cors());
app.use(bodyParser());

app.use('/user', userRoutes)

export default app;

server

import app from './app';
import { AppDataSource } from './src/database/Config';

async function connection() {
    const port = process.env.PORT;
    try {
        await AppDataSource.initialize();
        console.log('Database connected! ');
        app.listen(port);
        console.log(`Listening on port ${port}`)
    } catch (error) {
        console.log(error);
    }
}

connection();
0 Answers
Related