cookie MW added
This commit is contained in:
parent
4cf112ad5e
commit
476e5edf38
4 changed files with 17 additions and 2 deletions
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ import (
|
|||
type Router interface {
|
||||
Set() *gin.Engine
|
||||
AuthMW() gin.HandlerFunc
|
||||
RefreshMW() gin.HandlerFunc
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue