haskell-servant / haskell-servant/servant-js

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

Open
#48 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
23
Forks
22
PR merge metrics
No merged PRs in 30d

Description

I have an endpoint that looks approximately like this:
```hs
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:
```hs
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)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.