this is code for loginByEmail:
async function loginByEmail(email, callback) {
const { Client } = require(‘pg’);
const connectionString = ‘’;
const client = new Client({
connectionString: connectionString
});
try {
await client.connect();
const query = ‘SELECT id, nickname, email FROM users WHERE email = $1’;
const result = await client.query(query, [email]);
// Check if any rows were returned
if (result.rows.length === 0) {
return callback(new Error('User not found'));
}
const user = result.rows[0];
callback(null, {
user_id: user.id,
nickname: user.nickname,
email: user.email
});
} catch (err) {
callback(err);
} finally {
await client.end();
}
}
Here is the Code for the Create User:
function create(user, callback) {
const bcrypt = require(‘bcrypt’);
const { Pool } = require(‘pg’);
const conString = ‘’;
const pool = new Pool({
connectionString: conString
});
bcrypt.hash(user.password, 10, function (err, hashedPassword) {
if (err) {
pool.end(); // End the pool connection if an error occurs
return callback(err);
}
const query = ‘INSERT INTO users (nickname, email, password) VALUES ($1, $2, $3)’;
pool.query(query, [“test”, user.email, hashedPassword], function (err, result) {
pool.end(); // End the pool connection after executing the query
if (err) {
return callback(err);
} else {
return callback(null); // Pass the result to the callback
}
});
});
}
while testing the create User Script in custom database connection i am getting user not found error