about summary refs log tree commit diff
path: root/src/Types.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-29T13·14+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-29T13·14+0100
commitc4a090e55803864c21e8c40432ca17772247ca8e (patch)
tree3085b8e1f323830ad0b62bbae93fb27b24729046 /src/Types.hs
parent9f70cb2c612212e218b5df75c9afba08f51d3acb (diff)
Support reading / writing cookies in API
Update my API type and handler types to reflect which handlers read and write
cookies.

TODO:
- Actually read from and write to Set-Cookie header
- Returning `pure NoContent` breaks my types, so I'm returning `undefined` now
Diffstat (limited to 'src/Types.hs')
-rw-r--r--src/Types.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Types.hs b/src/Types.hs
index d33ea6870f13..eed9bf8c1696 100644
--- a/src/Types.hs
+++ b/src/Types.hs
@@ -14,6 +14,8 @@ import Database.SQLite.Simple.Ok
 import Database.SQLite.Simple.FromField
 import Database.SQLite.Simple.ToField
 import GHC.Generics
+import Web.Cookie
+import Servant.API
 import Crypto.Random.Types (MonadRandom)
 
 import qualified Crypto.KDF.BCrypt as BC
@@ -382,3 +384,11 @@ data LoginAttempt = LoginAttempt
 
 instance FromRow LoginAttempt where
   fromRow = LoginAttempt <$> field <*> field
+
+newtype SessionCookie = SessionCookie Cookies
+
+instance FromHttpApiData SessionCookie where
+  parseHeader x =
+    x |> parseCookies |> SessionCookie |> pure
+  parseQueryParam x =
+    x |> TE.encodeUtf8 |> parseCookies |> SessionCookie |> pure