TypeError: ConnectionConfig is not a constructor

Viewed 208

Hello I keep getting the error of TypeError: ConnectionConfig is not a constructor on line 22 and I cant figure out why. Im using the mysql package. So I hope someone can help me fix this issue because I dont know whats causing it. Thanks.

//3rd party modules
import bcrypt from "bcrypt";
import mysql from "mysql";

//Interfaces
import { Sql } from "./interfaces/sql.interface";
import { SqlTable } from "./interfaces/table.interface";
import { User } from "./interfaces/user.interface";

//Classes
import LoginAuth from "./loginAuth";

class UserAuth {
  user: string;
  password: string;
  sqlconnection: Sql;
  table: SqlTable;
  hashedPass: string;
  registeredUser!: User;

  constructor(
    user: string,
    password: string,
    sqlconnection: Sql,
    table: SqlTable
  ) {
    this.user = user;
    this.password = password;
    this.sqlconnection = sqlconnection;
    this.table = table;
    this.hashedPass = "";
  }

  registerUser() {
    bcrypt.genSalt(10, (err, salt) => {
      bcrypt.hash(this.password, salt, (err, hash) => {
        this.hashedPass = hash;
        const connection = mysql.createConnection({
          host: this.sqlconnection.host,
          user: this.sqlconnection.user,
          password: this.sqlconnection.password,
          database: this.sqlconnection.database,
        });
        connection.connect();
        this.registeredUser = {
          username: this.user,
          password: this.hashedPass,
        };
        connection.query(
          `INSERT INTO ${this.table.table} SET ?`,
          this.registeredUser
        );
      });
    });
  }
}

export default UserAuth;

0 Answers
Related