Pre registration user deny access

Hello.

So i try to set pre user registration action that will check to company database before registering new account.
From log activity i can confirm that the action is working, the problem is event when its return api.accrs.deny user can still pass the registration process.

Here is my code.


is there any extra step to do?
const mysql = require(‘mysql’);

exports.onExecutePreUserRegistration = async (event, api) => {
const connection = mysql.createConnection({
host: xxxxx,
user: ‘xxxx’,
password: xxxx,
database: xxxx,
port: xxx
});

connection.connect();

const checkEmployee = ‘SELECT Employee.id AS id, Employee.name AS nickname, Users.employeeId AS employeeId, Users.email AS email, Contacts.email AS contactEmail FROM db_employee.Employees Employee LEFT JOIN db_auth.Users Users ON Employee.id = Users.employeeId LEFT JOIN db_employee.Contacts Contacts ON Employee.id = Contacts.employeeId WHERE Contacts.email = ?’;

await connection.query(checkEmployee, [event.user.email], async function(err, results) {
console.log(results)
console.log(“here”)
try {
console.log(“here”)
if (err) return api.access.deny(“sql_error”,err);
if (results.length < 1) {api.access.deny(“employee_not_found”,“employee data not found”);}
console.log(“here”)
} catch (e){
api.access.deny(‘Could not create user doc’);
}
})
}

Hi @fakhrulraharjo

You are missing return statement in the catch(e) block.

Let us know if this helps

Thanks
Jeff

Okay leet me try it and give u an update