feat(handler): add AuthHandler.RevokeCurrent
This commit is contained in:
@@ -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 "
|
||||
|
||||
Reference in New Issue
Block a user