Skip to content

Commit

Permalink
chapter 05: making authentication depending of a concrete class of us…
Browse files Browse the repository at this point in the history
…erProvider, dependency inversion still is been violated
  • Loading branch information
devcorpio committed Mar 31, 2019
1 parent 7043373 commit a6f1b3b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function authentication(userProvider) {
function checkCredentials(username, password) {
const user = userProvider.findUser(username);

if (user === null) {
new Error('User not found');
}

//validate password...
}

return {
checkCredentials,
};
}

module.exports = authentication;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function userProvider(connection) {
function findUser(username) {
return connection.fetchAssoc('SELECT * FROM users WHERE username = ?', [
username,
]);
}

return {
findUser,
};
}

module.exports = userProvider;

0 comments on commit a6f1b3b

Please sign in to comment.