I think the biggest problem with your function is that it tries to handle three things at once:
- Checking if username and password are valid for a user (
credential-fn
andverify-pw
) - Cleaning up the record data
(dissoc user-record password)
- Building a Ring response map (
{:status 401}
vs.{:status 200 :body user-record}
)
I would consider splitting your code into two separate functions:
(defn authenticate
[username password]
(and (verify-pw password)
(dissoc (credential-fn username) :password)))
(defn login
[username password]
(if-let [user-record (authenticate username password)]
{:status 200 :body user-record}
{:status 401}))