Fork me on GitHub
#reitit
<
2020-06-11
>
sudakatux18:06:26

has anyone integrated buddy access rules with reitit

sudakatux18:06:18

i would like to know whats the best way of doing it because it seems to me i could somehow define the access rule in the route itself

sudakatux18:06:36

instead of having a separate function.

sudakatux18:06:03

Im currently doing it before the router with a middleware

sudakatux18:06:07

(def rules
  [{:uri "/api/user/*"
    :handler authenticated-or-preflight?}
   {:uri "/api/identity"
    :handler authenticated-or-preflight?}])

(defn on-error
  [request value]
  {:status 403
   :headers {
             "Content-Type" "text"
             }
   :body "Not authorized"})


(defn my-authfn
  [__ token]
  (session-store/get-user-from-store token))

(def backend (backends/token {:authfn my-authfn}))

(defn wrap-base [handler]
  (-> ((:middleware defaults) handler)
      (wrap-access-rules {:rules rules :on-error on-error})
      ;(wrap-authorization auth-backend)
      (wrap-authentication backend)

sudakatux18:06:11

I was wondering if there is a way i could define it in the route itself using a reitit middlware

sudakatux19:06:32

found an example of what i was looking here https://github.com/lipas-liikuntapaikat/lipas

emil0r20:06:46

Is there any way to have routes in reitit that are on the same level in the hierarchy?

emil0r20:06:00

I’d like to be able to have /word/add and /word/1 for the URI, but reitit is telling me it’s not allowed

ikitommi20:06:35

@emil0r just add :conflicts nil.

emil0r20:06:11

In the router options itself?

ikitommi20:06:27

reitit will use linear router and match the first one. for router options

ikitommi20:06:55

the exception should have that info in the message

emil0r20:06:14

Cool. works

emil0r20:06:46

Mostly needed it for breadcrumbs so that I can easily decide a hierarchal structure

emil0r20:06:00

Hmm… I really need to learn to look for cljdoc. I’m too used to readme’s

gekkostate21:06:04

Hi all, quick question. Is there an idiomatic way to do route restrictions on the front end? For the moment, I am designating some routes as public in my routes and then my router component, is filtering in/out the public routes.