summaryrefslogtreecommitdiff
path: root/pkg/ui/views/api.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-17 17:46:39 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-17 17:46:39 +0200
commit9cd48c660231592f3f8d9a035d45b568d987616e (patch)
tree5d6adb401f1697a78230f9931e9682be30cbdf95 /pkg/ui/views/api.go
parent3ad0d21e072c7461ea78a9a85111e6e19d3b0632 (diff)
Show icon for win/lose/draw on play landing page
Diffstat (limited to 'pkg/ui/views/api.go')
-rw-r--r--pkg/ui/views/api.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/ui/views/api.go b/pkg/ui/views/api.go
index 3788f91..ba202c8 100644
--- a/pkg/ui/views/api.go
+++ b/pkg/ui/views/api.go
@@ -6,6 +6,8 @@ import (
"fmt"
"net/http"
"os"
+
+ "github.com/boozec/rahanna/internal/api/auth"
)
// getAuthorizationToken reads the authentication token from the .rahannarc file
@@ -29,6 +31,22 @@ func getAuthorizationToken() (string, error) {
return authorization, nil
}
+// From a JWT token it returns the associated user ID
+func getUserID() (int, error) {
+ token, err := getAuthorizationToken()
+ if err != nil {
+ return -1, err
+ }
+
+ claims, err := auth.ValidateJWT("Bearer " + token)
+ if err != nil {
+ return -1, err
+ }
+
+ return claims.UserID, nil
+
+}
+
// sendAPIRequest sends an HTTP request to the API with the given parameters
func sendAPIRequest(method, url string, payload []byte, authorization string) (*http.Response, error) {
req, err := http.NewRequest(method, url, bytes.NewReader(payload))