In custom DB creating a user

Hello,
Greetings of the day.
I am a beginner laravel dev. i have encountered with below msg.
“[SandboxUnhandledError] mysql is not a function”.

my code
const connection = mysql({
host: ‘d2c6ec27.ngrok.io’,
user: ‘root’,
password: ‘’,
port: ‘3306’,
database: ‘hotstarapp’
});
an also i have tried with
const connection = mysql.createConnection({
host: ‘d2c6ec27.ngrok.io’,
user: ‘root’,
password: ‘’,
port: ‘3306’,
database: ‘hotstarapp’
});
but no luck.
plz tell me what is the issue. thanks in advance.

Hi. I don’t know what Laravel has to do with this as that is JavaScript code.

I am going to assume you are using Laravel as your backend and some frontend library that communicates with it…

It’s very clear what your error is. mysql() is not a function. Nobody here can actually help you, because you have not given us any information to do so.

You will need to consult the documentation of your frontend librar(y/ies) for information on how to connect to your MySQL database.

This question is not auth0 specific.

I am using auth0’s custom DB connection. with own custom DB feature.
i am try to connect my local db with it.
On click of TRY link the below error is showing.
“[SandboxUnhandledError] mysql is not a function”.
And in the Real-time webtask. the below message is showed.
{
“code”: 500,
“error”: “Script generated an unhandled synchronous exception.”,
“details”: “TypeError: mysql is not a function”,
“name”: “TypeError”,
“message”: “mysql is not a function”,
“stack”: “TypeError: mysql is not a function\n at getByEmail (/data/io/c6efb891-6882-4a64-b906-d9471f16da8f/webtask.js:9:22)\n at /data/io/c6efb891-6882-4a64-b906-d9471f16da8f/webtask.js:31:2\n at Async.waterfall (/data/sandbox/lib/sandbox.js:617:33)\n at nextTask (/data/sandbox/node_modules/async/dist/async.js:5324:14)\n at next (/data/sandbox/node_modules/async/dist/async.js:5331:9)\n at /data/sandbox/node_modules/async/dist/async.js:969:16\n at Async.waterfall (/data/sandbox/lib/sandbox.js:506:24)\n at nextTask (/data/sandbox/node_modules/async/dist/async.js:5324:14)\n at next (/data/sandbox/node_modules/async/dist/async.js:5331:9)\n at /data/sandbox/node_modules/async/dist/async.js:969:16”
}

Most probably mysql library is not loaded in the custom db script correctly. Can you try to include the import statement and explicitly set the version number. For example:

var mysql =require('mysql@2.15.0')

List of supported package can be found here: Can I require? - Search which node modules you can use in webtask.io

how can i include that thing in a template which is on auth0’s side?

You can include the import statement before initializing mysql.



function login(email, password, callback) {
var mysql =require('mysql@2.15.0');

  var connection = mysql({
    host: 'localhost',
    user: 'me',
    password: 'secret',
    database: 'mydb'
  });

  connection.connect();


callback(null)
}

import ‘mysql’; //latest is 2.18.1
function create(user, callback) {

const mysql = require(‘mysql@2.18.1’);
const bcrypt = require(‘bcrypt’);

const connection = mysql.createConnection({
host: ‘d2c6ec27.ngrok.io’,
user: ‘root’,
password: ‘’,
port :‘3306’,
database: ‘hotstarapp’
});
ERROR:-“[SandboxUnhandledError] Invalid response code from the auth0-sandbox: HTTP 400. Unexpected token import”

I do not think v2.18.1 is supported. It is not listed here: Can I require? - Search which node modules you can use in webtask.io

Try one of the version listed in that link.

i tried all of them but no luck. plz guide me. i am confused very much.