Align GoChat with Chatwoot frontend contracts

This commit is contained in:
2026-06-13 22:13:32 +08:00
parent 71abf58636
commit d884fdda0a
162 changed files with 9825 additions and 528 deletions
+6 -3
View File
@@ -32,9 +32,12 @@ func AuthMiddleware(cfg *config.JWTConfig) gin.HandlerFunc {
func AuthMiddlewareWithService(jwtSvc *auth.JWTService) gin.HandlerFunc {
return func(c *gin.Context) {
authHeader := c.GetHeader("Authorization")
if authHeader != "" {
chatwootAccessToken := strings.TrimSpace(c.GetHeader("access-token"))
if authHeader != "" || chatwootAccessToken != "" {
tokenString := strings.TrimPrefix(authHeader, "Bearer ")
if tokenString == authHeader {
if authHeader == "" {
tokenString = chatwootAccessToken
} else if tokenString == authHeader {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "bearer token required"})
return
}
@@ -105,4 +108,4 @@ func GenerateToken(cfg *config.JWTConfig, userID uint, accountID uint, role stri
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString([]byte(cfg.Secret))
}
}