This commit is contained in:
Mats Rauhala 2018-08-28 22:24:54 +03:00
parent 526a2e7ebc
commit 8d8b4e0453
2 changed files with 5 additions and 1 deletions

View File

@ -55,7 +55,7 @@ instance FromJSON JsonBook
instance ToJSON PostBook
instance FromJSON PostBook
type API = Auth '[SA.BasicAuth, SA.JWT] SafeUser :> BaseAPI
type API = Auth '[TokenCheck, SA.BasicAuth, SA.JWT] SafeUser :> BaseAPI
type BaseAPI = "books" :> Get '[JSON] [JsonBook]
:<|> "books" :> ReqBody '[JSON] PostBook :> Post '[JSON] JsonBook

View File

@ -6,10 +6,12 @@
{-# Language DuplicateRecordFields #-}
{-# Language TypeApplications #-}
{-# Language TemplateHaskell #-}
{-# Language FlexibleContexts #-}
module Server.Auth
( SafeUser(..)
, authCheck
, AuthResult(..)
, TokenCheck
, requireLoggedIn)
where
@ -56,3 +58,5 @@ authCheck app (BasicAuthData username password) = flip runReaderT app $
requireLoggedIn :: (MonadLogger m, MonadThrow m, Monad m) => (SafeUser -> m a) -> AuthResult SafeUser -> m a
requireLoggedIn f (Authenticated user) = f user
requireLoggedIn _ u = $logError (pack (show u)) >> throwM err401
data TokenCheck