From 88d101a0c587edaa8e3b2ffd24964c8cfb54f2b7 Mon Sep 17 00:00:00 2001 From: Tri Anggi Anggara Saputra Date: Fri, 12 Jul 2024 07:37:53 +0700 Subject: [PATCH] feat: Add role_code to auth context --- internal/delivery/middleware/auth.go | 9 +++++++++ internal/model/base/context.go | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/delivery/middleware/auth.go b/internal/delivery/middleware/auth.go index 018e363..449f300 100644 --- a/internal/delivery/middleware/auth.go +++ b/internal/delivery/middleware/auth.go @@ -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) diff --git a/internal/model/base/context.go b/internal/model/base/context.go index bba2d3d..4294f4f 100644 --- a/internal/model/base/context.go +++ b/internal/model/base/context.go @@ -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 {