From 1d019d905ba9b35596f72eb568cfe7a212db4308 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 17 Jan 2024 09:02:13 -0500 Subject: [PATCH] fix: use a type switch --- api/s5/middleware.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api/s5/middleware.go b/api/s5/middleware.go index 391dbb4..06d3db5 100644 --- a/api/s5/middleware.go +++ b/api/s5/middleware.go @@ -41,12 +41,26 @@ func AuthMiddleware(handler jape.Handler, portal interfaces.Portal) jape.Handler } if claim, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { - userID, ok := claim["sub"].(uint64) + subject, ok := claim["sub"] + if !ok { http.Error(w, "Invalid User ID", http.StatusBadRequest) return } + var userID uint64 + + switch v := subject.(type) { + case uint64: + userID = v + case float64: + userID = uint64(v) + default: + // Handle the case where userID is of an unexpected type + http.Error(w, "Invalid User ID", http.StatusBadRequest) + return + } + exists, _ := portal.Accounts().AccountExists(userID) if !exists {