fix: use a type switch

This commit is contained in:
Derrick Hammer 2024-01-17 09:02:13 -05:00
parent af71f68ea9
commit 1d019d905b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 1 deletions

View File

@ -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 {