Is there anyone who knows, how it can be use the custom user authentication? I tried with the example (with little modification of course) but it not works. Here is my custom js:
module.exports = {
type: "credentials",
authenticate: function(username,password) {
return new Promise(function(resolve) {
var ok=false;
if(username=="Admin"&&password=="destiny5562"){
ok=true;
}
else{
ok=false;
}
if (ok==true) {
// Resolve with the user object. Equivalent to having
// called users(username);
var user = { username: "admin", permissions: "*" };
resolve(user);
} else {
// Resolve with null to indicate the username/password pair
// were not valid.
resolve(null);
}
});
},
}
And in my settings.js the only thing i do that, just enabled the adminAuth:
adminAuth: require("./user-authentication"),
When try to log in, browser dev console throw this when i use good username and password
@Steve-Mcl@TotallyInformation I tried, what you suggested me and it's worked. So for that, i tried to make a more complicated custom auth. What i want the achive is a custom auth which working with mysql. Here is look like now:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "smh"
});
module.exports = {
type: "credentials",
users: function(username) {
return new Promise(function(resolve) {
con.connect(function(err) {
con.query("SELECT * FROM users WHERE username ='"+username+"'", function (err, result, fields) {
if (err) throw err;
if (result.length!=0) {
// Resolve with the user object. It must contain
// properties 'username' and 'permissions'
var user = {username: result[0].username, permissions: result[0].permission};
resolve(user);
} else {
// Resolve with null to indicate this user does not exist
resolve(null);
}
});
});
});
},
authenticate: function(username,password) {
return new Promise(function(resolve) {
con.connect(function(err) {
con.query("SELECT * FROM users WHERE username ='"+username+"' AND password='"+password+"'", function (err, result, fields) {
if (err) throw err;
if (result.length!=0) {
// Resolve with the user object. Equivalent to having
// called users(username);
var user = { username:result[0].username, permissions: result[0].permissions};
resolve(user);
} else {
// Resolve with null to indicate the username/password pair
// were not valid.
resolve(null);
}
});
});
});
},
default: function() {
return new Promise(function(resolve) {
// Resolve with the user object for the default user.
// If no default user exists, resolve with null.
resolve({anonymous: true, permissions:"read"});
});
}
}
The problem with that code is basicly the same with the that one that i posted. If i pass the good username and password it didn't allow me the enter i got 401 error, but if i pass a wrong one 403 error. So the situation is the same at was before.