Hello everyone. I am new to Auth0 and wanted to try it as an authentication method for a small web app I’m making.
I am using my own MySQL database and the respective MySQL script template for the Create action.
I’ve made a username required for signing up and have included it as “user.username” in the script to be added to my database.
When I test the script and provide my username, email and password, I get the error “missing username for Username-Password-Authentication connection with requires_username enabled”.
Here is the code where the username is included:
const query = 'INSERT INTO users SET ?';
const insert = {
password: hash,
email: user.email,
nickname: user.username
};
connection.query(query, insert, function (err, results) {
if (err) return callback(err);
if (results.length === 0) return callback();
callback(null);
});
Can someone clarify if the message means no username was entered while testing the script, or no username was received as parameter to insert into the database?
When I test my app and try to create an account I get “Something went wrong, please try again later”.
Thanks for your help and suggestions! Let me know if you have any questions.
Hi there @dimitar10000 ,
Can you please test your script when '‘requires username’ is disabled for the Username-Password-Authentication connection and after removing the nickname: user.username
from your insert? Is it working?
As far as I remember, the limitation of custom database scripts is that they do not support users.username property.
1 Like
Hey.
Apologies for the late reply. I tried it by removing the nickname field in all scripts, removed it from my database as well.
When I test the create script now it throws a “[SandboxUnhandledError] mysql is not a function” error.
I looked into other posts in the forum, but the solutions don’t seem to work here. I am using this code in the template:
const mysql = require('mysql');
const bcrypt = require('bcrypt');
const connection = mysql.createConnection({
host: configuration.MYSQL_HOST,
user: 'root',
password: configuration.MYSQL_PASSWORD,
database: 'shop-db'
});
connection.connect();
Also, when trying to create a user in the app, it again says “Something went wrong, please try again later”.
Is the error related to the script or something else? Let me know if you need more info.
Okay, update to my post. I enabled attributes in the Attributes menu and selected “Use Email as Identifier” there, so this somehow resolved the previous error.
Now I am getting “getaddrinfo ENOTFOUND” whenever I test the create script again. What could be causing this? I am using the host name which I verified with “SHOW VARIABLES WHERE Variable_name = ‘hostname’” in my MySQL shell.
What name/address should I be using to access my local DB instance?
Hi there @dimitar10000 ,
I also did some more research, and it looks like the endpoints to which the scripts will connect must be available over the Internet.
You could consider checking this tool - https://ngrok.com/
Please let me know if that helps or reach out with questions you may have along the way.
Hey again.
I checked out Ngrok and after trying different things I got this from a connection which should make the local database publicly accessible from what I understand:
tcp://0.tcp.eu.ngrok.io:11910
The problem is that when I use this in my script:
const connection = mysql.createConnection({
host: configuration.MYSQL_HOST,
user: 'root',
password: configuration.MYSQL_PASSWORD,
port: '11910',
database: 'shop-db'
});
and the host is set to “0.tcp.eu.ngrok.io”, it throws an error “ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client”.
Are you familiar with Ngrok and what I should actually do to be able to access the endpoint from Auth0? Thanks.