zohl / servant-auth-cookie

Authentication via encrypted cookies
BSD 3-Clause "New" or "Revised" License
23 stars 23 forks source link

CookiedWrapperClass bound to `Handler a`? #44

Closed michalrus closed 6 years ago

michalrus commented 6 years ago

If someone doesn’t want to use the ExceptT err IO a (anti-)pattern (→ https://www.fpcomplete.com/blog/2016/11/exceptions-best-practices-haskell), what should they do?

Right now, we’re applying this patch in default.nix to servant-auth-cookie, so that’s not very inconvenient, but… I don’t know. ¯\_(ツ)_/¯

diff --git a/src/Servant/Server/Experimental/Auth/Cookie.hs b/src/Servant/Server/Experimental/Auth/Cookie.hs
index 4102941..9ebaa4f 100644
--- a/src/Servant/Server/Experimental/Auth/Cookie.hs
+++ b/src/Servant/Server/Experimental/Auth/Cookie.hs
@@ -779,7 +779,7 @@ class CookiedWrapperClass f r c where

 -- When no arguments left: add session header to result.
 instance (Serialize c)
-         => CookiedWrapperClass (Handler b) (Handler (Cookied b)) c where
+         => CookiedWrapperClass (IO b) (IO (Cookied b)) c where
   wrapCookied _               Nothing                    = fmap noHeader
   wrapCookied (acs, rs, k, _) (Just PayloadWrapper {..}) = (>>= addSession acs rs k pwSettings pwSession)
michalrus commented 6 years ago

And also → http://www.parsonsmatt.org/2017/06/21/exceptional_servant_handling.html.

zohl commented 6 years ago

Hi!

Thank you for the links, I've pushed the commit that will fix it. I didn't pay attention to enter functionality of servant and natural transformations, and therefore assumed "default" monad, i.e. Handler.

Right now it should accept any of MonadIO and MonadThrow, so you don't have to patch it anymore.

michalrus commented 6 years ago

Wonderful! :tada:

I’ll check it out tomorrow at work.

Thank you very much! :heart_eyes_cat:

(Re: enter → not really relevant, but it was deprecated in favor of hoistServerWithContext.)

michalrus commented 6 years ago

I confirm this works, thank you once more for your wonderful support!