from remote-desktop 4 tháng trước cách đây
mục cha
commit
f99ae290b5
1 tập tin đã thay đổi với 16 bổ sung15 xóa
  1. 16 15
      src/api/user.go

+ 16 - 15
src/api/user.go

@@ -43,23 +43,24 @@ func forwardRequestWithJWT(c *gin.Context, targetURL string) (interface{}, error
 
 	req.Header.Set("Authorization", jwtToken)
 
-	// Copy the original content type, unless it's the set-password endpoint
-	if strings.Contains(targetURL, "/api/set-password") {
-		req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
-		// Parse JSON body and convert to form data
-		if len(bodyBytes) > 0 {
-			var jsonData map[string]interface{}
-			if err := json.Unmarshal(bodyBytes, &jsonData); err != nil {
-				return nil, fmt.Errorf("parse json error: %v", err)
+	if c.Request.Method == "POST" {
+		if strings.Contains(targetURL, "/api/set-password") {
+			req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+			// Parse JSON body and convert to form data
+			if len(bodyBytes) > 0 {
+				var jsonData map[string]interface{}
+				if err := json.Unmarshal(bodyBytes, &jsonData); err != nil {
+					return nil, fmt.Errorf("parse json error: %v", err)
+				}
+				formData := url.Values{}
+				for k, v := range jsonData {
+					formData.Set(k, fmt.Sprintf("%v", v))
+				}
+				req.Body = io.NopCloser(strings.NewReader(formData.Encode()))
 			}
-			formData := url.Values{}
-			for k, v := range jsonData {
-				formData.Set(k, fmt.Sprintf("%v", v))
-			}
-			req.Body = io.NopCloser(strings.NewReader(formData.Encode()))
+		} else {
+			req.Header.Set("Content-Type", "application/json")
 		}
-	} else if c.Request.Method == "POST" {
-		req.Header.Set("Content-Type", "application/json")
 	}
 
 	// Accept gzip encoding