updating rest-api

This commit is contained in:
2026-07-17 11:56:13 -05:00
parent 39433a0044
commit c4d7f52d37
15 changed files with 276 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
package middlewares
import (
"net/http"
"example.com/rest-api/utils"
"github.com/gin-gonic/gin"
)
func Authenticate(context *gin.Context) {
token := context.Request.Header.Get("Authorization")
if token == "" {
context.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"message": "Not authorized"})
return
}
userId, err := utils.VerifyToken(token)
if err != nil {
context.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"message": "Not authorized"})
}
context.Set("userId", userId)
context.Next()
}