package auth import ( "nixcn-cms/internal/exception" "nixcn-cms/service/service_auth" "nixcn-cms/utils" "github.com/gin-gonic/gin" ) // Refresh handles the token rotation process. // // @Summary Refresh Access Token // @Description Accepts a valid refresh token to issue a new access token and a rotated refresh token. // @Tags Authentication // @Accept json // @Produce json // @Param payload body service_auth.RefreshData true "Refresh Token Body" // @Success 200 {object} utils.RespStatus{data=service_auth.TokenResponse} "Successful rotation" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" // @Failure 401 {object} utils.RespStatus{data=nil} "Invalid Refresh Token" // @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" // @Router /auth/refresh [post] func (self *AuthHandler) Refresh(c *gin.Context) { var refreshData service_auth.RefreshData if err := c.ShouldBindJSON(&refreshData); err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceAuth). SetEndpoint(exception.EndpointAuthServiceRefresh). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorInvalidInput). SetError(err). Throw(c). String() utils.HttpResponse(c, 400, errorCode) return } result := self.svc.Refresh(&service_auth.RefreshPayload{ Context: c, Data: &refreshData, }) if result.Common.Exception.Original != exception.CommonSuccess { utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String()) return } utils.HttpResponse(c, 200, result.Common.Exception.String(), result.Data) }