Question

how to carry out an authentication process for each request sent. The problem i'm currently facing is i'm not able access user data which is sent as a request param. here is what i have tried

(pre-route[:any "/mainpage/*"] {:keys[data]}
 (when (not(contains? data "userid"))
   //false response
  )
)

and the middleware

(defn for-auth [handler]

  (fn [req]
    (if (contains? (:body (:params req)))
      (handler req)
      (handler (assoc req :body {})
    )
   )
)

and i add the middlware too. but neither of them work.. Any idea to access user params..

Thanks

Was it helpful?

Solution 2

Ok here is what i have done and it solves my problem..

(pre-route [:any "/mainroute/*"] {{:keys [jsondata]}:params}
  (let [data (httputil/parse-json-data jsondata)]

  (cond
    (not (true? valid_req)) "false"
    (not (true? version_check)) "false"
    (not (true? user_valid)) "false"
    )
   )
  )

here i have parsed my json data in middleware and added it to "params" with key name :jsondata.. it works perfectly..

OTHER TIPS

Sandy

Are you using wrap params?

.. (:use [ring.middleware params])

(def app (-> (handler/site main-routes) (wrap-base-url) (wrap-params)))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top