fix: use a type switch
This commit is contained in:
parent
af71f68ea9
commit
1d019d905b
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue