I have created tapir endpoint:
val getEndpoint = endpoint.get
.securityIn(auth.bearer[String]())
.in("players" / path[PlayerId]("playerId"))
.in(query[PlayerRequest]("query"))
.errorOut(someErrors)
Now, I would like to read all passed values: bearer token, playerId and query. So I created ZIO server logic:
PlayersEndpoint.getEndpoint.zServerLogic { case (playerId, query) =>
//some logic to do...
}
It works fine, but whithout bearer token. Here I could not read bearer token. I tried to change it to something like:
PlayersEndpoint.getEndpoint.zServerSecurityLogic{ case (token) =>
//do smth with token
}.zServerLogic { case (playerId, query) =>
//some logic to do...
}
But it did not work. I would like to read all 3 values and decide about what to do after checking token. Docs and examples are very poor and do not show how to read tokens from tapir. Do you know how I should do it correctly?
I don't have IDE to give you the exact code but the idea is that the return of your
zServerSecurityLogiccan be used in the followingzServerLogic.Usually you'd validate the token in the
zServerSecurityLogicand return some kind ofUservalue that you can use as input inzServerLogic.But you can also "do nothing" in the security logic and just passthrough the token so that it's available in the main logic.