Skip to content

Generating clients for JWT example in cookbook #1873

@khazaddum

Description

@khazaddum

Hello,

I'm following the Servant Cookbook example to combine Basic authentication with JWT. My server works but when trying to generate client functions, I keep getting an error similar to #558

[typecheck] • Couldn't match type: Token
                       -> (RegisterPayload -> ClientM RegisterResponse)
                          :<|> (ClientM LoginResponse :<|> ClientM TestPayload)
                 with: (Token -> RegisterPayload -> ClientM RegisterResponse)
                       :<|> ((Token -> ClientM LoginResponse)
                             :<|> (Token -> ClientM TestPayload))
  Expected: ClientM ServerStatus
            :<|> ((Token -> RegisterPayload -> ClientM RegisterResponse)
                  :<|> ((Token -> ClientM LoginResponse)
                        :<|> (Token -> ClientM TestPayload)))
    Actual: Client ClientM API
• In the expression: client $ (Proxy :: Proxy API)
  In a pattern binding:
    checkStatus :<|> (basicRegister :<|> basicLogin :<|> basicTest)
      = client $ (Proxy :: Proxy API)
type PublicAPI =
  "status" :> Description "Provide server status" :> Get '[JSON] ServerStatus

type ManagedAPI =
  "register"
    :> Description "Create a user"
    :> ReqBody '[JSON] RegisterPayload
    :> PostCreated '[JSON] RegisterResponse
    :<|> "login"
      :> Description "Log in with existing user"
      :> Post '[JSON] LoginResponse
    :<|> "tokentest"
      :> Description "Test JWT auth"
      :> Get '[JSON] TestPayload

type API =
  PublicAPI
    :<|> Auth '[SA.JWT, SA.BasicAuth] AuthenticatedUser :> (ManagedAPI)

checkStatus :: ClientM ServerStatus
basicRegister :: Token -> RegisterPayload -> ClientM RegisterResponse
basicLogin :: Token -> ClientM LoginResponse
basicTest :: Token -> ClientM TestPayload
checkStatus :<|> (basicRegister :<|> basicLogin :<|> basicTest) = client $ (Proxy :: Proxy API)

Shouldn't the Token parameter get distributed to all the client functions under ManagedAPI?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions