title: Authentication middleware not working in Gin
body: <p>I have the following routes and the session setup:</p>
  <pre><code>func SetupRouter() *gin.Engine {
      r := gin.Default()
  
      // Session
      store := cookie.NewStore([]byte(&quot;secret&quot;))
      // Set session expiration time
      store.Options(sessions.Options{MaxAge: 3600 * 24}) // 24hr
      r.Use(sessions.Sessions(&quot;mysession&quot;, store))
  
      r.GET(&quot;api/business/&quot;, controllers.GetBusiness)
      r.POST(&quot;api/business/login&quot;, controllers.Login)
      r.GET(&quot;api/business/logout&quot;, controllers.Logout)
      r.GET(&quot;api/business/session&quot;, controllers.GetBusinessSession)
      r.POST(
          &quot;api/itemcategory/add&quot;, 
          // isBusinessAuth(), 
          controllers.CreateItemCategory,
      )
      r.POST(
          &quot;api/itemcategory/delete/:id&quot;,
          // isBusinessAuth(),
          controllers.DeleteItemCategory,
      )
      r.GET(
          &quot;api/itemcategory/all&quot;,
          // isBusinessAuth(),
          controllers.GetAllItemCategories,
      )
      r.POST(
          &quot;api/itemcategory/update/:id&quot;,
          // isBusinessAuth(),
          controllers.CreateItemCategory,
      )
  
      return r
  }
  </code></pre>
  <p>the <code>isBusinessAuth()</code> function:</p>
  <pre><code>func isBusinessAuth() gin.HandlerFunc {
      return func(c *gin.Context) {
          if sessions.Default(c).Get(&quot;businessAuth&quot;) == 1 {
              c.Next()
              return
          } else {
              c.JSON(http.StatusUnauthorized, gin.H{&quot;error&quot;: &quot;You are not authorized!&quot;})
          }
          c.Abort()
          return
      }
  }
  </code></pre>
  <p>This is how session is placed, in the Login function:</p>
  <pre><code>// Set business session
  session.Set(&quot;businessAuth&quot;, 1)
  session.Save()
  </code></pre>
  <p>No matter what value has the session, <code>isBusinessAuth()</code> is returning &quot;You are not authorized&quot; for all the routes where is used. I tried to put it on &quot;/api/business/login&quot; and &quot;/api/business/session&quot; routes and there is working as expected. What am I missing?</p>
  <p>Thank you :)</p>