feat(parity): align Chatwoot 4.15.1 contracts
This commit is contained in:
@@ -158,6 +158,10 @@ func (h *AuthHandler) ChatwootSignIn(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := h.trackChatwootSession(c, output); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to create session")
|
||||
return
|
||||
}
|
||||
|
||||
h.setChatwootAuthHeaders(c, output)
|
||||
profile, err := h.chatwootUserPayload(c, output.User.ID, output.AccountID)
|
||||
@@ -212,7 +216,7 @@ func (h *AuthHandler) ChatwootSignOut(c *gin.Context) {
|
||||
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "invalid token")
|
||||
return
|
||||
}
|
||||
if err := h.authService.Logout(c.Request.Context(), output.User.ID); err != nil {
|
||||
if err := h.authService.RevokeChatwootSession(c.Request.Context(), output.User.ID, c.GetHeader("client")); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "Logout failed")
|
||||
return
|
||||
}
|
||||
@@ -357,6 +361,10 @@ func (h *AuthHandler) ConfirmResetPassword(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"message": err.Error(), "redirect_url": "/"})
|
||||
return
|
||||
}
|
||||
if err := h.trackChatwootSession(c, output); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to create session")
|
||||
return
|
||||
}
|
||||
|
||||
h.setChatwootAuthHeaders(c, output)
|
||||
data, err := h.chatwootUserPayload(c, output.User.ID, output.AccountID)
|
||||
@@ -404,6 +412,10 @@ func (h *AuthHandler) ChatwootConfirmEmail(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"message": err.Error(), "redirect_url": "/"})
|
||||
return
|
||||
}
|
||||
if err := h.trackChatwootSession(c, output); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to create session")
|
||||
return
|
||||
}
|
||||
|
||||
h.setChatwootAuthHeaders(c, output)
|
||||
data, err := h.chatwootUserPayload(c, output.User.ID, output.AccountID)
|
||||
@@ -533,10 +545,18 @@ func (h *AuthHandler) setChatwootAuthHeaders(c *gin.Context, output *service.Log
|
||||
return
|
||||
}
|
||||
c.Header("access-token", output.TokenPair.AccessToken)
|
||||
c.Header("client", output.TokenPair.RefreshToken)
|
||||
clientID := output.ClientID
|
||||
if clientID == "" {
|
||||
clientID = output.TokenPair.RefreshToken
|
||||
}
|
||||
c.Header("client", clientID)
|
||||
c.Header("expiry", strconv.FormatInt(output.TokenPair.ExpiresAt.Unix(), 10))
|
||||
}
|
||||
|
||||
func (h *AuthHandler) trackChatwootSession(c *gin.Context, output *service.LoginOutput) error {
|
||||
return h.authService.TrackChatwootSession(c.Request.Context(), output, c.GetHeader("client"), c.ClientIP(), c.GetHeader("User-Agent"))
|
||||
}
|
||||
|
||||
func extractChatwootAccessToken(c *gin.Context) string {
|
||||
if token := strings.TrimSpace(c.GetHeader("access-token")); token != "" {
|
||||
return token
|
||||
|
||||
Reference in New Issue
Block a user