Skip to content

Commit ed00a64

Browse files
committed
chapter 05: authentication is not depending in connection anymore, now depends in an abstraction
1 parent a6f1b3b commit ed00a64

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

chapter-05-the-dependency-inversion-principle/refactor/userProvider.js renamed to chapter-05-the-dependency-inversion-principle/refactor/MySQLUserProvider.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
function userProvider(connection) {
1+
/**
2+
* @implements {UserProviderInterface}
3+
*/
4+
function mysqlUserProvider(connection) {
25
function findUser(username) {
36
return connection.fetchAssoc('SELECT * FROM users WHERE username = ?', [
47
username,
@@ -10,4 +13,4 @@ function userProvider(connection) {
1013
};
1114
}
1215

13-
module.exports = userProvider;
16+
module.exports = mysqlUserProvider;

chapter-05-the-dependency-inversion-principle/refactor/authentication.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* In order to improve the understanding of this code, this file it is supposing to implement the following interface:
3+
*
4+
* interface UserProviderInterface {
5+
* function findUser(username);
6+
* }
7+
*
8+
* Quack Quack Quack 🦆 typing :D
9+
*/
10+
11+
/**
12+
* @param {UserProviderInterface} userProvider
13+
*/
114
function authentication(userProvider) {
215
function checkCredentials(username, password) {
316
const user = userProvider.findUser(username);

0 commit comments

Comments
 (0)