feat(handler): add AuthHandler.RevokeCurrent

This commit is contained in:
Голиков Maximillian Антон
2026-10-02 10:08:53 +03:00
parent 537ec40c8a
commit 00d3c0feed
+18
View File
@@ -9,6 +9,7 @@ import (
"high-loud-apps-labs/internal/domain"
"high-loud-apps-labs/internal/httpapi/dto"
"high-loud-apps-labs/internal/httpapi/middleware"
"high-loud-apps-labs/internal/service"
)
@@ -36,6 +37,23 @@ func (h *AuthHandler) CreateSession(c *gin.Context) {
c.JSON(http.StatusCreated, dto.SessionResponseFromDomain(session, token, user))
}
// RevokeCurrent отзывает текущую сессию. Токен уже проверен BearerAuth,
// поэтому здесь его достаточно передать в SessionService.
func (h *AuthHandler) RevokeCurrent(c *gin.Context) {
token := middleware.CurrentToken(c)
if token == "" {
respondError(c, &domain.UnauthorizedError{Reason: "нет токена"})
return
}
if err := h.sessions.Revoke(c.Request.Context(), token); err != nil {
respondError(c, err)
return
}
c.Status(http.StatusNoContent)
}
// parseBasicAuth читает Authorization: Basic base64(username:password).
func parseBasicAuth(c *gin.Context) (string, string, error) {
const prefix = "Basic "