From 87ebf5012beaf17fda31d63b28aee8996f04f392 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 15 Jan 2024 22:53:12 -0500 Subject: [PATCH] fix: policies need to be added after --- api/casbin.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/casbin.go b/api/casbin.go index cccc62f..b8b47b7 100644 --- a/api/casbin.go +++ b/api/casbin.go @@ -18,15 +18,16 @@ func GetCasbin(logger *zap.Logger) *casbin.Enforcer { a := NewPolicyAdapter(logger) - _ = a.AddPolicy("admin", "/admin", []string{"GET"}) - _ = a.AddPolicy("admin", "/admin", []string{"POST"}) - _ = a.AddPolicy("admin", "/admin", []string{"DELETE"}) - e, err := casbin.NewEnforcer(m, a) if err != nil { logger.Fatal("Failed to create casbin enforcer", zap.Error(err)) } + // Add policies after creating the enforcer + _ = a.AddPolicy("admin", "/admin", []string{"GET"}) + _ = a.AddPolicy("admin", "/admin", []string{"POST"}) + _ = a.AddPolicy("admin", "/admin", []string{"DELETE"}) + return e }