summaryrefslogtreecommitdiff
path: root/pkg/ui/views/api.go
diff options
context:
space:
mode:
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))