refactor(middleware): lab2 put CurrentUser/CurrentToken from auth to context.go
This commit is contained in:
@@ -9,8 +9,6 @@ import (
|
||||
"high-loud-apps-labs/internal/httpapi/dto"
|
||||
)
|
||||
|
||||
const CurrentUserKey = "current_user"
|
||||
|
||||
func Auth(users domain.UserRepository) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
id := c.GetHeader("X-User-Id")
|
||||
@@ -30,15 +28,6 @@ func Auth(users domain.UserRepository) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func CurrentUser(c *gin.Context) *domain.User {
|
||||
if v, ok := c.Get(CurrentUserKey); ok {
|
||||
if u, ok := v.(*domain.User); ok {
|
||||
return u
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func abortUnauthorized(c *gin.Context, msg string) {
|
||||
reqID := GetRequestID(c)
|
||||
body := dto.ErrorFromDomain(
|
||||
|
||||
Reference in New Issue
Block a user