servant-auth
servant-auth copied to clipboard
`ThrowAll` and `EmptyServer`
I can't seem to use throwAll with an API type containing an EmptyServer anywhere in it. I have a MonadError ServantErr m instance for my monad stack (below) and throwAll works for other types of routes.
Here's a minimal reproduction:
newtype AppT m a
= AppT
{ runApp :: ReaderT Environment (ExceptT ServantErr m) a
} deriving ( Functor, Applicative, Monad, MonadReader Environment,
MonadError ServantErr, MonadIO)
data ApiUser = ApiUser
{ UserId :: Int64
} deriving (Eq, Show, Generic, ToJSON, FromJSON)
instance ToJWT ApiUser
instance FromJWT ApiUser
type MyAPI auths = Auth auths ApiUser :> EmptyAPI
myPrivateServer :: MonadIO m => AuthResult ApiUser -> ServerT EmptyAPI (AppT m)
myPrivateServer (Authenticated _user) = emptyServer
myPrivateServer _ = throwAll err401
This unfortunately gives me the following error:
Could not deduce (Control.Monad.Error.Class.MonadError
ServantErr (Tagged (AppT m)))
arising from a use of ‘throwAll’
from the context: MonadIO m
bound by the type signature for:
myPrivateServer :: MonadIO m =>
AuthResult ApiUser -> ServerT EmptyAPI (AppT m)
Out of curiosity, what happens if you apply hoistServer to your throwAll err401 — so the throwAll is operating in Handler, say?
(Curious because I've been experimenting with that approach, but I don't know how well it actually works.)
what happens if you apply hoistServer to your throwAll err401
I'm not sure. Right now I am using the lts-9.21 snapshot in stack, which has servant version 0.11 and I believe hoistServer was added after that.
I may take a crack at upgrading to the new lts-11.4 snapshot, which looks like it has the latest servant-0.13 in it. I'll report back when I do that.