Add License

This commit is contained in:
aditya.siregar
2024-07-29 22:30:29 +07:00
parent 6a987f78b9
commit f645f23fd4
9 changed files with 82 additions and 30 deletions
+20
View File
@@ -61,3 +61,23 @@ func SuperAdminMiddleware() gin.HandlerFunc {
c.Next()
}
}
func IsAdminMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
ctx, exists := c.Get("myCtx")
if !exists {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
c.Abort()
return
}
myCtx, ok := ctx.(*mycontext.MyContextImpl)
if !ok || !myCtx.IsAdmin() {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
c.Abort()
return
}
c.Next()
}
}