-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapter 05: making authentication depending of a concrete class of us…
…erProvider, dependency inversion still is been violated
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
chapter-05-the-dependency-inversion-principle/refactor/authentication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
13 changes: 13 additions & 0 deletions
13
chapter-05-the-dependency-inversion-principle/refactor/userProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |