haskell-servant / haskell-servant/servant
Is it possible to change the request's vault from within the `route` function?
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
I'm trying to write a custom Auth combinator, which will decrypt a cookie and get the userId from it. After that it will look up the DB and ensure that the userId has been granted specified roles. A sample usage:
```
type Api = EnsureAuth "SuperAdmin" :> "admin" :> "billing" :> Post '[JSON] Billing
:<|> EnsureAuth "Support" :> "admin" :> "customers" :> Get '[JSON] [Customer]
```
I have managed to write my DB pool into the app's context, and used it from within the `route` function of my combinator. However, apart from passing the authorization result to the Handler, I also want to store it in the request's vault, so that it can be use by other middleware components (eg. logging and Airbrake error reporting). Is this possible? Is this a good idea?
The other solution I can think of, is to write a middleware which does the authorisation and stores the result in the vault, and the combinator's `route` function fetches the authorisation result from the vault. The possible downside with this approach is that we have multiple authorisation schemes. Unless we know which route we are about to serve, we don't know which authorisation code to execute. If I move this part to a middleware, I will be forced to try all possible authorisation schemes (and store the results to the vault), even though we will eventually need only one.
Contributor guide
Assessment
This issue has not been assessed yet.