Skip to content

Commit 7e52260

Browse files
committed
README: Add info on auth protected routes
1 parent 458f50d commit 7e52260

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ In an actual project we would be writing the code to disk instead of printing it
129129

130130
See [this file](examples/UserAPI.hs) for the full code with imports.
131131

132+
## Auth-protected routes
133+
134+
If you use `AuthProtect` from `Servant.API.Experimental.Auth`, the following
135+
code can be used:
136+
137+
```haskell
138+
instance HasElmEndpoints api => HasElmEndpoints (AuthProtect "auth" :> api) where
139+
elmEndpoints' = elmEndpoints' @(Header' '[ Required, Strict] "Authorization" Token :> api)
140+
```
141+
142+
This makes endpoints under `AuthProtect "auth"` take an extra `Token` parameter
143+
which are added as authorization headers to the requests. This assumes that
144+
`Token` has appropriate instances for `HasElmType` and `HasElmEncoder Text`.
145+
132146
## Related projects
133147

134148
Libraries that use or are used by servant-to-elm:

0 commit comments

Comments
 (0)