Align GoChat with Chatwoot frontend contracts
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user