The Database Action Scripts should follow the format:
function xxxxxx (params..., callback) {
(...) Your logic (...)
return callback(null, profile);
}
In your script, I see that you start right away with var MD5 = function (s) {
which is why you’re getting the Unexpected token var error. As an example, the login script should be something like:
function login (email, password, callback) {
var connection = mysql({
host: 'localhost',
user: 'me',
password: 'secret',
database: 'mydb'
});
connection.connect();
var query = "SELECT id, nickname, email, password " +
"FROM users WHERE email = ?";
connection.query(query, [email], function (err, results) {
if (err) return callback(err);
if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
var user = results[0];
bcrypt.compare(password, user.password, function (err, isValid) {
if (err) {
callback(err);
} else if (!isValid) {
callback(new WrongUsernameOrPasswordError(email));
} else {
callback(null, {
id: user.id.toString(),
nickname: user.nickname,
email: user.email
});
}
});
});
}
For the login script, there are three ways it can finish:
1. The user's credentials are valid. The returned user profile should be in the following format: https://auth0.com/docs/user-profile/normalized
var profile = {
user_id: ..., // user_id is mandatory
email: ...,
...]
};
callback(null, profile);
2. The user's credentials are invalid
callback(new WrongUsernameOrPasswordError(email, "my error message"));
3. Something went wrong while trying to reach your database
callback(new Error("my error message"));
You can check more detailed information about the database action scripts here: Custom Database Connections