Skip to content

Commit

Permalink
fix(cli): resolve authentication bug (#94)
Browse files Browse the repository at this point in the history
cli would reject all logins with `530 Cannot destructure property `password` of 'undefined' or 'null'.` because the credentials object was being indexed with `[object Object]`. Even with that fixed, if the username was not found, it would produce that error.
  • Loading branch information
alancnet authored and trs committed Jun 8, 2018
1 parent 1cf1f75 commit 1f15af0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function setupState(_args) {
_state.credentials = {};

const setCredentials = (username, password, root = null) => {
_state.credentials[_state.credentials] = {
_state.credentials[username] = {
password,
root
};
Expand All @@ -72,7 +72,7 @@ function setupState(_args) {
const credentialsFile = path.resolve(_args.credentials);
const credentials = require(credentialsFile);

for (const cred of Object.entries(credentials)) {
for (const cred of credentials) {
setCredentials(cred.username, cred.password, cred.root);
}
} else if (_args.username) {
Expand All @@ -97,9 +97,9 @@ function setupState(_args) {
function startFtpServer(_state) {

function checkLogin(data, resolve, reject) {
const {password, root} = _state.credentials[data.username];
if (_state.anonymous || password === data.password) {
return resolve({root: root || _state.root});
const user = _state.credentials[data.username]
if (_state.anonymous || (user && user.password === data.password)) {
return resolve({root: (user && user.root) || _state.root});
}

return reject(new errors.GeneralError('Invalid username or password', 401));
Expand Down

0 comments on commit 1f15af0

Please sign in to comment.