For my react app I have a sign in component that we want to call a signup function that is held in a separate dbUtils file, the functions work when the file is run by itself but when it is called in the react component I am getting the error message.
TypeError: Net.createConnection is not a function
71 | this._connectCalled = true;
72 |
73 | // Connect either via a UNIX domain socket or a TCP socket.
> 74 | this._socket = (this.config.socketPath)
| ^ 75 | ? Net.createConnection(this.config.socketPath)
76 | : Net.createConnection(this.config.port, this.config.host);
77 |
This is the SignIn.js component in our react app
import * as db from '../utils/dbUtils.js';
const SignInModal = ({ showSignIn, setShowSignIn }) => {
// ---- ERROR FURTHER BELOW ----
const modalRef = useRef();
const [showSignUp, setShowSignUp] = useState(false);
function submitForm() {
if (showSignUp) {
db.signUp();
}
setShowSignIn(false);
values.email = '';
values.username = '';
values.password = '';
values.password2 = '';
}
useEffect(
() => {
document.addEventListener('keydown', keyPress);
db.initCon(); //<----------------------- ERROR OCCURS HERE -------------
return () => document.removeEventListener('keydown', keyPress);
},
[keyPress]
);
return (
<>
<div>lots of html</div>
</>
);
}
export default SignInModal
this is the javascript file containing our sql injection logic dbUtils.js
var mysql = require('mysql');
var connection;
var loggedIn = false;
var currAccId;
export function initCon(){
connection = mysql.createConnection({
host : '---', // <-- taken out for this post
user : '---',
password : '---'
});
connection.connect();
}
export function endConn(){
connection.end();
}
export function signUp(dispName, email, pw){
connection.query("INSERT INTO typeTestdb.user_table (display_name,user_email,password) VALUES (?,?,?);",[dispName, email, pw], function (error, results) {
if (error) {
console.log("Email already registered! Try logging in!");
} else {
console.log('Account Created');
}
});
}