diff --git a/svc/pkg/handler/user.go b/svc/pkg/handler/user.go index 7e8222f..bae15a3 100644 --- a/svc/pkg/handler/user.go +++ b/svc/pkg/handler/user.go @@ -1,6 +1,7 @@ package handler import ( + "a-project-backend/gen/gModel" "a-project-backend/gen/gQuery" "a-project-backend/pkg/config" "a-project-backend/pkg/gcs" @@ -45,18 +46,13 @@ func NewUser(db *gorm.DB, g *gcs.GCS) User { // GetMe Meユーザーの取得 func (h User) GetMe() gin.HandlerFunc { return func(c *gin.Context) { - uAny, exists := c.Get(middleware.AuthorizedUserIDField) + uAny, exists := c.Get(middleware.AuthorizedUserField) if !exists { c.AbortWithStatusJSON(500, gin.H{"error": "userId not set"}) } - - u, err := h.q.User.Where(h.q.User.FirebaseUID.Eq(uAny.(string))).First() - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - c.AbortWithStatusJSON(404, gin.H{"error": err.Error()}) - } else { - c.AbortWithStatusJSON(500, gin.H{"error": err.Error()}) - } + u, ok := uAny.(gModel.User) + if !ok { + c.AbortWithStatusJSON(500, gin.H{"error": "user not castable"}) } tags := make([]*pb_out.Tag, len(u.Tags)) diff --git a/svc/pkg/middleware/auth.go b/svc/pkg/middleware/auth.go index 747c321..fe845a6 100644 --- a/svc/pkg/middleware/auth.go +++ b/svc/pkg/middleware/auth.go @@ -13,6 +13,7 @@ import ( const ( AuthorizedUserIDField = "AuthorizedUserID" + AuthorizedUserField = "AuthorizedUser" ) type auth struct { @@ -64,6 +65,7 @@ func (a auth) VerifyUser() gin.HandlerFunc { } c.Set(AuthorizedUserIDField, u.UserID) + c.Set(AuthorizedUserField, *u) c.Next() } }