ADD: added new auth middleware and changed the roles value ind the jwt token to a array

This commit is contained in:
hwinkel
2025-11-23 22:55:04 +01:00
parent 139a99d96e
commit 3a6c3a86e3
9 changed files with 84 additions and 30 deletions

View File

@@ -35,8 +35,8 @@ func LoginHandler(c *gin.Context, db *sql.DB) {
// Systemnutzer
var token string
var err error
if req.Email == "test@localhost.de" {
token, err = CreateJWT("system-user-id", req.Email, "admin", 60*time.Minute)
if req.Email == "test@localhost.de" { //nolint:goconst
token, err = CreateJWT("system-user-id", req.Email, []string{"admin"}, 60*time.Minute)
} else {
hash, err := common.HashPassword(req.Password)
@@ -55,7 +55,7 @@ func LoginHandler(c *gin.Context, db *sql.DB) {
return
}
// Create JWT token
token, err = CreateJWT(loggedInPlayer.UUID, req.Email, "player", 60*time.Minute)
token, err = CreateJWT(loggedInPlayer.UUID, req.Email, []string{"player"}, 60*time.Minute)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token creation error"})
return