fix(backend,frontend) remake update profile
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user