Skip to content

Commit

Permalink
Merge pull request #54 from openhacku-team-a/fix-shion-hot
Browse files Browse the repository at this point in the history
🚑️
  • Loading branch information
Shion1305 authored Mar 16, 2024
2 parents 0ab5117 + f8dca53 commit 4ffb68a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 5 additions & 9 deletions svc/pkg/handler/user.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions svc/pkg/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

const (
AuthorizedUserIDField = "AuthorizedUserID"
AuthorizedUserField = "AuthorizedUser"
)

type auth struct {
Expand Down Expand Up @@ -64,6 +65,7 @@ func (a auth) VerifyUser() gin.HandlerFunc {
}

c.Set(AuthorizedUserIDField, u.UserID)
c.Set(AuthorizedUserField, *u)
c.Next()
}
}
Expand Down

0 comments on commit 4ffb68a

Please sign in to comment.