Servant Set Cookie by Server

Hello, I would like a simple example about how to set session cookies by the server. Instead of just returning “ok”, I would like the server to also create a “sessionToken” cookie.

I have found this Servant Cookie Doc, but it seems to be complicated without an example.

performLoginServer :: PostgresConnection -> Server PerformLoginProxy
performLoginServer conn (LoginForm username password) = do
  userMaybe <- liftIO $ do getUserMaybe conn username password
  case userMaybe of
    Just user -> return "ok"
    Nothing -> throwError $ err401
2 Likes

I actually wrote this very recently as a standalone example:

This should be exactly what you are looking for

1 Like