Fork me on GitHub
#reitit
<
2022-07-17
>
craftybones05:07:24

I've a question on routing interceptors. I'm using sieppari . I want to handle auth by routing a request back to /login if user is not logged in. Would I use a routing interceptor here? If not, what would you recommend?

craftybones05:07:25

in general, how is rerouting accomplished?

craftybones06:07:23

Should I simply have an interceptor that modifies a handler if auth fails?

craftybones07:07:57

The following works, but is this what you'd recommend

(if-not logged-in?
    (assoc ctx :queue
           (conj clojure.lang.PersistentQueue/EMPTY
                 (into-interceptor unauthorized-handler))))

craftybones07:07:26

I guess I could also get the handler I want by querying the router by name

craftybones15:07:53

What I really want is for an interceptor to pre-empt a response and not take the request all the way to the handler. Still wondering how this is done.

craftybones15:07:07

I've looked at the examples, but not found one

lispyclouds15:07:59

@srijayanth i guess https://github.com/metosin/sieppari/blob/develop/src/sieppari/context.cljc#L26 would do it? adding something like (s/terminate {:status 403, :body "You shall not pass here!"}) as the response in your interceptor may just do it?

craftybones15:07:02

I thought so too

craftybones15:07:21

Which is Pedestal's

craftybones15:07:24

I'll check it out

lispyclouds15:07:19

doesnt look like the one released on clojars has this fn

lispyclouds15:07:12

maybe i guess add the body of the terminate to your handler

craftybones15:07:14

Actually, I have no idea if it is on clojars. In fact, I've not directly added sieppari as a dependency. Just depending on What reitit has

craftybones15:07:43

Anyway, it does work, and it is exactly what I want. Thanks

lispyclouds15:07:14

nice! i guess sieppari the repo, could be behind

craftybones15:07:20

Worked! Thanks a ton. I was poking around in the executor