fix(backend,frontend) remake update profile

This commit is contained in:
2026-05-09 11:42:41 +03:00
parent fe331026aa
commit 92e440deb0
14 changed files with 508 additions and 91 deletions
+18 -3
View File
@@ -35,14 +35,29 @@ func AuthRequired() gin.HandlerFunc {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid or expired token"})
c.Abort()
return
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
c.Set("user_id", claims["user_id"])
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
if id, ok := claims["user_id"].(float64); ok {
c.Set("user_id", uint(id))
}
c.Set("role", claims["role"])
}
c.Next()
}
}
func AdminOnly() gin.HandlerFunc {
return func(c *gin.Context) {
role, exists := c.Get("role")
if !exists || role != "Админ" {
c.JSON(http.StatusForbidden, gin.H{"error": "Доступ ограничен"})
c.Abort()
return
}
c.Next()
}
}