Fork me on GitHub
#reitit
<
2022-04-25
>
grahamcarlyle16:04:23

I'm wondering whether there is a way to use the controllers facility in reitit-frontend within a re-frame app to record the original route that an as yet unauthorised user navigates to, send a user to a login route then after successful authentication send the app back to the original route? I've got the redirect working by firing a re-frame event on the controllers for routes that require an authenticated session, the event handler then push-states the app to the login route if no auth session exists. but i'm not clear whether its possible to determine the original route within the controller so that it can pass this along with the re-frame event to be recorded and then restored when the login completes.

wevrem17:04:08

I’m curious what responses you get, @grahamcarlyle, because I don’t know of a “built-in” solution for this, so I rolled my own, but I don’t know that it is very elegant. Maybe there is something out there that addresses this issue better.

weavejester18:04:36

Is there any documentation on what the :options argument in reitit.coercion.malli/create takes?

weavejester18:04:54

I assumed that it was the same as the options you could pass to a Malli validator, but it looks like that isn’t the case.

weavejester18:04:51

Is there a way of assigning a custom registry to Malli coercion?

ikitommi18:04:15

@weavejester see https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj#L87-L97 and the source of. reitit.coercion.malli/create. the docs are lagging, PRs most welcome

weavejester18:04:11

Hey @ikitommi, I’ve been looking at the source but I haven’t been able to get it to work. My current attempt is: (reitit.coercion.malli/create {:options {:registry …}})

weavejester18:04:54

Unfortunately I get the rather opaque :malli.core/invalid-schema error

weavejester18:04:43

I’ve simplified it down to: (reitit.coercion.malli/create {:options {:registry {::email :string}}}), but that still says it’s an invalid schema :data {:schema :map} so I’m doing something wrong.

ikitommi18:04:55

:thinking_face: can you make a minimal gist/repro. I can look in the morning.

weavejester18:04:46

No problem. I’ll plug away at this a little myself first, and see if I can’t figure it out 🙂

weavejester19:04:15

Maybe this is a Malli problem…

weavejester19:04:48

Aha, yes, solved it. I was assuming that the Malli :registry key worked the same way as an option to malli.core/validator as it does when included in a :schema block. What I needed to do was:

(reitit.coercion.malli/create {:options {:registry (mr/registry (merge (m/default-schemas) {::email :string}))}})

👍 1