authorized.go 315 B

12345678910111213141516
  1. package middleware
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // Authorized blocks unauthorized requestrs
  7. func Authorized(c *gin.Context) {
  8. _, exists := c.Get("parentId")
  9. if !exists {
  10. c.JSON(http.StatusUnauthorized, gin.H{"status": http.StatusUnauthorized, "message": "must login"})
  11. c.Abort()
  12. }
  13. }