Skip to content

Commit

Permalink
fetch the discord avatar url and show it
Browse files Browse the repository at this point in the history
  • Loading branch information
humorless committed Aug 8, 2024
1 parent ffb4014 commit a319afc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/co/gaiwan/compass/db/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[:discord/access-token :string "Discord OAuth2 access-token"]
[:discord/expires-at :instant "Expiration timestamp for the OAuth2 token"]
[:discord/refresh-token :string "Discord OAuth2 refresh-token"]
[:discord/avatar-url :string "Discord Avatar URL"]

[:session/title :string "Title of the talk/workshop/activity"]
[:session/subtitle :string "Subtitle of the session, for talks/workshops = speaker names"]
Expand Down
6 changes: 3 additions & 3 deletions src/co/gaiwan/compass/html/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

(o/defstyled profile-detail :div#detail
[image-frame :w-100px]
([{:discord/keys [access-token id refresh-token expires-at]
:user/keys [email handle name uuid title image] :as user}]
([{:discord/keys [access-token id refresh-token expires-at avatar-url]
:user/keys [email handle name uuid title image-url] :as user}]
[:<>
[image-frame {:profile/image
(if image
(if-let [image (or image-url avatar-url)]
(str "url(" image ")")
(str "var(--gradient-" (inc (rand-int 7)) ")"))} user]
[:div.details
Expand Down
13 changes: 8 additions & 5 deletions src/co/gaiwan/compass/routes/oauth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@
[:pre (util/pprint-str body)]]
:session {:identity nil}}
(let [{:keys [access_token refresh_token expires_in]} body
{:keys [id global_name email username]} (fetch-user-info access_token)
{:keys [id global_name email username] :as user-info} (fetch-user-info access_token)
avatar-url (str "https://cdn.discordapp.com/avatars/" id "/" (:avatar user-info) ".png")
;;_ (prn :avatar-url avatar-url)
user-uuid (:user/uuid (d/entity (db/db) [:user/email email]) (random-uuid))
tx-data
[{:user/uuid user-uuid
:user/email email
:user/name global_name
:user/handle username
:discord/avatar-url avatar-url
:discord/id id
:discord/access-token access_token
:discord/refresh-token refresh_token
:discord/expires-at (.plusSeconds (java.time.Instant/now) (- expires_in 60))}]]
(def tx-data tx-data)
@(db/transact tx-data )
@(db/transact tx-data)
{:status 302
:headers {"Location" (or redirect-url "/")}
:flash [:p "You are signed in!"]
Expand All @@ -74,6 +77,6 @@
["/logout"
{:get {:handler (fn [req]
(assoc
(response/redirect "/")
:flash "You were signed out"
:session {}))}}]])
(response/redirect "/")
:flash "You were signed out"
:session {}))}}]])

0 comments on commit a319afc

Please sign in to comment.