better login page

This commit is contained in:
2026-05-29 10:55:14 -07:00
parent 3441ae63b4
commit 6814cf1b15
6 changed files with 209 additions and 182 deletions

View File

@@ -66,9 +66,9 @@
])
(defn not-found [_]
{:status 404
{:status 404
:headers {}
:body ""})
:body ""})
(defn home-handler [{:keys [identity]}]
(if identity
@@ -125,13 +125,13 @@
(defn wrap-logging [handler]
(fn [request]
(mu/with-context (cond-> {:uri (:uri request)
:route (:handler (bidi.bidi/match-route all-routes
(:uri request)
:request-method (:request-method request)))
(mu/with-context (cond-> {:uri (:uri request)
:route (:handler (bidi.bidi/match-route all-routes
(:uri request)
:request-method (:request-method request)))
:client-selection (:client-selection request)
:source "request"
:source "request"
:query (:uri request)
:request-method (:request-method request)
:user (dissoc (:identity request)
@@ -157,15 +157,15 @@
(defn wrap-idle-session-timeout
[handler]
(fn [request]
(let [session (:session request {:version session-version/current-session-version})
(let [session (:session request {:version session-version/current-session-version})
end-time (coerce/to-date-time (::idle-timeout session))]
(if (and end-time (time/before? end-time (time/now)))
(if (get (:headers request) "hx-request")
{:session nil
:status 200
:status 200
:headers {"hx-redirect" "/login"}}
{:session nil
:status 302
:status 302
:headers {"Location" "/login"}})
(when-let [response (handler request)]
(let [session (:session response session)]
@@ -231,7 +231,7 @@
seq
(pull-many (dc/db conn)
'[:db/id :client/name :client/code :client/locations
:client/matches :client/feature-flags
:client/matches :client/feature-flags
{:client/bank-accounts [:db/id
{:bank-account/type [:db/ident]}
:bank-account/number
@@ -298,7 +298,7 @@
{:status 200
:headers {"hx-trigger" (cheshire/generate-string
{"notification" (str (hiccup/html [:div (.getMessage e)]))})
"hx-reswap" "none"}} ;; TODO make a warning box so you don't have to reuse the notifaction box, or make it reuse the same box but theme differently
"hx-reswap" "none"}} ;; TODO make a warning box so you don't have to reuse the notifaction box, or make it reuse the same box but theme differently
:else
{:status 500
:body (pr-str e)})))))
@@ -315,32 +315,48 @@
:valid-trimmed-client-ids trimmed-clients
:first-client-id (first valid-clients)
:clients-trimmed? (not= (count trimmed-clients) (count valid-clients)))))))
(defn wrap-dev-login [handler]
(fn [request]
(if (and (= "/dev-login" (:uri request))
(some-> env :base-url (.contains "localhost")))
(let [identity {:user "Dev User"
:user/name "Dev User"
:user/role "admin"
:db/id 0}]
{:status 200
:headers {"Content-Type" "text/html"}
:body "<p>Logged in as Dev User!</p><a href='/dashboard'>Continue to dashboard</a>"
:session {:identity identity
:version session-version/current-session-version}})
(handler request))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defonce app
(-> route-handler
(wrap-hx-current-url-params)
(wrap-guess-route)
(wrap-logging)
(wrap-trim-clients)
(wrap-hydrate-clients)
(wrap-store-client-in-session)
(wrap-gunzip-jwt)
(wrap-authorization auth-backend)
(wrap-authentication auth-backend
(session-backend {:authfn (fn [auth]
(dissoc auth :exp))}))
(-> route-handler
(wrap-hx-current-url-params)
(wrap-guess-route)
(wrap-logging)
(wrap-trim-clients)
(wrap-hydrate-clients)
(wrap-store-client-in-session)
(wrap-gunzip-jwt)
(wrap-dev-login)
(wrap-authorization auth-backend)
(wrap-authentication auth-backend
(session-backend {:authfn (fn [auth]
(dissoc auth :exp))}))
#_(wrap-pprint-session)
#_(wrap-pprint-session)
(session-version/wrap-session-version)
(wrap-idle-session-timeout)
(wrap-session {:store (cookie-store
{:key
(byte-array
[42, 52, -31, 101, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])})})
(session-version/wrap-session-version)
(wrap-idle-session-timeout)
(wrap-session {:store (cookie-store
{:key
(byte-array
[42, 52, -31, 101, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])})})
#_(wrap-reload)
(wrap-params)
(mp/wrap-multipart-params)
(wrap-edn-params)
(wrap-error)))
#_(wrap-reload)
(wrap-params)
(mp/wrap-multipart-params)
(wrap-edn-params)
(wrap-error)))