haskell-servant / haskell-servant/servant

Add "AuthProtect" instances to servant-foreign

Open
#463 5 comments 0 reactions 0 assignees View on GitHub
servant-foreign
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

In order to generate JS functions that include the `Authorization` header when using `AuthProtect`. For my immediate use I looked at the instance for `Header` and hacked around it to create one for `AuthProtect`, although I don't know that it's a good idea to hard-code the type 'Text' or the header name 'Authorization'....

```
instance (KnownSymbol sym, HasForeignType lang ftype Text, HasForeign lang ftype sublayout)
=> HasForeign lang ftype (AuthProtect sym :> sublayout) where
type Foreign ftype (AuthProtect sym :> sublayout) = Foreign ftype sublayout

foreignFor lang Proxy Proxy req =
foreignFor lang Proxy subP $ req & reqHeaders <>~ [HeaderArg arg]
where
arg = Arg
{ _argName = PathSegment "Authorization"
, _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy Text) }
subP = Proxy :: Proxy sublayout
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.