Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sakuya-Izayoi opened this issue Jun 7, 2022 · 0 comments
Open

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

Sakuya-Izayoi opened this issue Jun 7, 2022 · 0 comments

Comments

@Sakuya-Izayoi
Copy link

Sakuya-Izayoi commented Jun 7, 2022

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant