cookie MW added

This commit is contained in:
nquidox 2025-09-14 19:33:09 +03:00
parent 4cf112ad5e
commit 476e5edf38
4 changed files with 17 additions and 2 deletions

View file

@ -42,7 +42,7 @@ func NewApp(deps Deps) *App {
for _, m := range app.modules {
if hasRoutes, ok := m.(interfaces.ModuleRoutes); ok {
hasRoutes.RegisterRoutes(apiRoutes, app.routerHandler.AuthMW())
hasRoutes.RegisterRoutes(apiRoutes, app.routerHandler.AuthMW(), app.routerHandler.RefreshMW())
}
}

View file

@ -8,5 +8,5 @@ type Module interface {
}
type ModuleRoutes interface {
RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc)
RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, refreshMW gin.HandlerFunc)
}

View file

@ -7,4 +7,5 @@ import (
type Router interface {
Set() *gin.Engine
AuthMW() gin.HandlerFunc
RefreshMW() gin.HandlerFunc
}

View file

@ -31,3 +31,17 @@ func (r *router) AuthMW() gin.HandlerFunc {
c.Next()
}
}
func (r *router) RefreshMW() gin.HandlerFunc {
return func(c *gin.Context) {
cookie, err := c.Request.Cookie("refresh_uuid")
if err != nil {
c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()})
log.WithError(err).Error("User | Failed to get refresh cookie")
return
}
c.Set("refresh_uuid", cookie.Value)
c.Next()
}
}