add: api key middleware

This commit is contained in:
$(pass /github/name)
2024-09-02 17:05:15 +02:00
parent 6ac2b32a1f
commit 1ad2f2090f
7 changed files with 121 additions and 35 deletions

View File

@@ -1,7 +1,6 @@
package controllers
import (
"GoMembership/internal/config"
"GoMembership/internal/models"
"GoMembership/internal/services"
@@ -28,19 +27,6 @@ func (mc *MembershipController) RegisterSubscription(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Couldn't decode subscription data"})
}
logger.Info.Printf("Using API key: %v", config.Auth.APIKEY)
if regData.APIKey == "" {
logger.Error.Println("API Key is missing")
c.JSON(http.StatusUnauthorized, "API Key is missing")
return
}
if regData.APIKey != config.Auth.APIKEY {
logger.Error.Printf("API Key not valid: %v", regData.APIKey)
c.JSON(http.StatusUnauthorized, "API Key is missing")
return
}
// Register Subscription
id, err := mc.Service.RegisterSubscription(&regData.Model)
if err != nil {