Skip to content

Cannot generate function for API's that use Servant.Auth #48

@Sakuya-Izayoi

Description

@Sakuya-Izayoi

I have an endpoint that looks approximately like this:

SAS.Auth [SAS.Cookie] LoggedIn :> Capture "tournamentId" TournamentId :> "start" :> Post '[JSON] (Entity Tournament)

Unfortunately, attempt to generate JS for this API does not typecheck. The error is:

app\Main.hs:24:14: error:
    * No instance for (servant-foreign-0.15.4:Servant.Foreign.Internal.HasForeign
                         NoTypes NoContent StartTournamentApi)
        arising from a use of `jsForAPI'
    * In the expression:
        jsForAPI (Proxy :: Proxy StartTournamentApi) jquery
      In an equation for `js':
          js = jsForAPI (Proxy :: Proxy StartTournamentApi) jquery
      In the expression:
        do let js = jsForAPI (Proxy :: Proxy StartTournamentApi) jquery
           TIO.writeFile "static/js/api.js" js
   |
24 |     let js = jsForAPI (Proxy :: Proxy StartTournamentApi) jquery

I assume that js generator should completely ignore auth requirement because XMLHttpRequest sends cookies which are used for authentication.

The workaround I found is to create a following instance:

instance HasForeign lang ftype api => HasForeign lang ftype (Auth auths val :> api) where
    type Foreign ftype (Auth auths val :> api) = Foreign ftype api
    foreignFor lang ftype Proxy = foreignFor lang ftype (Proxy :: Proxy api)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions