Fork me on GitHub
#reitit
<
2023-08-18
>
rickheere18:08:04

Hi everyone. I'm using reitit.ring and reitit.coercion.malli . I have an endpoint that needs to switch the schema bases on the authorization of the user. How can I dynamically switch the schema used for coercion? Would it be better to not use the middleware but run the coercion manually? Thanks

Ben Sless19:08:39

Can the authorization type be figured out before coercion?

rickheere19:08:20

I did not work on that code yet but I imagined doing that in a middleware that runs before coercion. And yeah in the middleware I can also update the schema's of course.

rickheere19:08:53

Thanks for the idea 😅

Ben Sless19:08:07

I'd add the authorization type as a field, then write a multi schema that dispatches on it

rickheere20:08:05

Hmm yeah, I looked it up and that is a cool idea.

rickheere20:08:37

But I like the idea of being able to construct a schema on the fly based on for example claims in an auth token. There will be many different users, claims map to schemas that need to be combined. The list of possible claims and schemas they map will grow. Lots of dynamic changes going on.

rickheere20:08:23

But yeah, still thinking about and working on the problem.