Hi I have set a custom database with an action script on the login event this is the code:
function login(email, password, callback) {
//this example uses the "pg" library
//more info here: https://github.com/brianc/node-postgres
const bcrypt = require('bcrypt');
const postgres = require('pg');
const conString = 'user://password:@host/database';
var pool = new postgres.Pool({connectionString: conString});
pool.connect(function (err, client, done) {
if (err) return callback(err);
const query = 'SELECT id, name, email, encrypted_password, handle FROM users WHERE email = $1';
client.query(query, [email], function (err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
if (err || result.rows.length === 0) return callback(err || new WrongUsernameOrPasswordError(email));
const user = result.rows[0];
bcrypt.compare(password, user.encrypted_password, function (err, isValid) {
if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));
return callback(null, {
user_id: user.id,
name: user.name,
email: user.email,
handle: user.handle
});
});
});
});
}
When I use the try connection
feature or the test on the custom database with a user and password stored on the db given on the connection string, it works oka and return the token with the user data, but If i try to loging to my spa app that I setted up connection with the custom db as a source, I can’t logging with the same user and password.
Shuld the user/password beeing able to login to my spa application ? Or maybe I missing something.