Skip to content

Commit

Permalink
chapter 05: authentication is not depending in connection anymore, no…
Browse files Browse the repository at this point in the history
…w depends in an abstraction
  • Loading branch information
devcorpio committed Mar 31, 2019
1 parent a6f1b3b commit ed00a64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function userProvider(connection) {
/**
* @implements {UserProviderInterface}
*/
function mysqlUserProvider(connection) {
function findUser(username) {
return connection.fetchAssoc('SELECT * FROM users WHERE username = ?', [
username,
Expand All @@ -10,4 +13,4 @@ function userProvider(connection) {
};
}

module.exports = userProvider;
module.exports = mysqlUserProvider;
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* In order to improve the understanding of this code, this file it is supposing to implement the following interface:
*
* interface UserProviderInterface {
* function findUser(username);
* }
*
* Quack Quack Quack 🦆 typing :D
*/

/**
* @param {UserProviderInterface} userProvider
*/
function authentication(userProvider) {
function checkCredentials(username, password) {
const user = userProvider.findUser(username);
Expand Down

0 comments on commit ed00a64

Please sign in to comment.