Skip to content

Commit

Permalink
feat: Add role_code to auth context
Browse files Browse the repository at this point in the history
  • Loading branch information
trianggianggara committed Jul 12, 2024
1 parent b44dd46 commit 88d101a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions internal/delivery/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ func Auth(next echo.HandlerFunc) echo.HandlerFunc {
email = ""
}

var roleCode string
destructRoleCode := token.Claims.(jwt.MapClaims)["role_code"]
if destructRoleCode != nil {
roleCode = destructRoleCode.(string)
} else {
roleCode = ""
}

authCtx := &baseModel.AuthContext{
ID: id,
Name: name,
Email: email,
RoleCode: roleCode,
}
ctx := ctxval.SetAuthValue(c.Request().Context(), authCtx)
newRequest := c.Request().WithContext(ctx)
Expand Down
7 changes: 4 additions & 3 deletions internal/model/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

type AuthContext struct {
ID uuid.UUID
Name string
Email string
ID uuid.UUID
Name string
Email string
RoleCode string
}

type TrxContext struct {
Expand Down

0 comments on commit 88d101a

Please sign in to comment.