Add Voucher Undian
This commit is contained in:
@@ -72,6 +72,34 @@ func CustomerAuthorizationMiddleware(cryp repository.Crypto) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func OptionalCustomerAuthorizationMiddleware(cryp repository.Crypto) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
tokenString := c.GetHeader("Authorization")
|
||||
if tokenString == "" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
tokenString = strings.TrimPrefix(tokenString, "Bearer ")
|
||||
|
||||
claims, err := cryp.ParseAndValidateJWTCustomer(tokenString)
|
||||
if err != nil {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
customCtx, err := mycontext.NewMyContextCustomer(c.Request.Context(), claims)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error initialize context"})
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("myCtx", customCtx)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func SuperAdminMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
ctx, exists := c.Get("myCtx")
|
||||
|
||||
Reference in New Issue
Block a user