Skip to content

Commit 4ccf3fe

Browse files
committed
roar
1 parent fb82d58 commit 4ccf3fe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/src/instant/util/posthog.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
[clojure.walk :as walk]
66
[instant.config :as config]
77
[instant.util.http :as http-util]
8-
[instant.util.tracer :as tracer])
8+
[instant.util.tracer :as tracer]
9+
[instant.model.instant-user :as instant-user-model])
910
(:import [com.posthog.server PostHog PostHogConfig PostHogInterface PostHogCaptureOptions]))
1011

1112
(defonce ^:private client (atom nil))
@@ -55,6 +56,14 @@
5556
(or (get-in request [:headers "x-instant-source"])
5657
"unknown"))
5758

59+
(defn req->auth-user
60+
"Extracts authenticated user from request. Returns nil if unauthenticated."
61+
[req]
62+
(when-let [refresh-token (http-util/req->bearer-token req)]
63+
(when (and refresh-token (parse-uuid refresh-token))
64+
(instant-user-model/get-by-refresh-token {:refresh-token refresh-token
65+
:auth? true}))))
66+
5867
(defn extract-tracking-context
5968
"Extract tracking context from a ring request.
6069
Automatically extracts auth user from request if present."

0 commit comments

Comments
 (0)