Fork me on GitHub
#beginners
<
2019-11-18
>
fastaction15:11:29

Does anyone here have healthy experience with middleware and reitit? I have been slamming my head against implementing authentication within reitit for weeks now. I feel like theres something small and stupid I'm missing. The origin of the problem is in basic-auth middleware within my user-login route. If anyone would take a peek and give their two cents, it may help immensely. https://github.com/mxjxn/eclecticlub/blob/master/src/clj/eclecticlub/routes/users.clj

henrik15:11:32

What’s the error?

fastaction16:11:51

It seems it's not actually using the basic-auth middleware. It goes straight to the auth middleware function, resulting in 401 unauthorized.

henrik16:11:52

Are they inserted in the right order? I believe Reitit uses the reverse order of Compojure.

ikitommi16:11:24

@U0Y53Q0R4 reitit applies the middleware in the order defined, so it looks to be correct. There is a request debugging option, prints out all the applied mw, and how they have changed the request/response. Here's how to enable it: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj#L67

ikitommi16:11:37

hope this helps.

❤️ 1
fastaction16:11:07

I discovered my problem was that I was passing the email and password parameters in the body, not in a header as buddy auth expected. Thanks for your help.

tdantas21:11:52

is it possible to run on REPL the Cognitect test runner ?

tdantas21:11:53

awesome. reading now the repo ! thanks Alex

alexmiller21:11:12

(require '[cognitect.test-runner :as tr])
(tr/-main <whatever-options-you-need>)

tdantas21:11:56

yep, just saw the repo, straightforward ! thx

alexmiller21:11:01

I guess there's a little trickiness there - being a main function, it takes a String[]

👍 1
alexmiller21:11:49

(tr/-main (into-array String ["-d" "test"]))

alexmiller21:11:56

something like that, didn't actually run it

tdantas21:11:13

let you know ! gonna try in a few seconds

alexmiller21:11:39

looks like you can also just call the test function directly, that's probably better

tdantas21:11:42

yeah

(let [{:keys [fail error]} (test (:options args))]

tdantas21:11:58

gonna try the test, just setting up my environment, thx for your time

vaer-k23:11:09

So if you call in-ns at the repl, you have to require and refer clojure.repl again? Is there any easier way to switch namespaces?

alexmiller23:11:27

Yes, and no respectively

vaer-k23:11:41

I forgot about use, I guess that’s a little easier