Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 17, 2023
1 parent 3fb4afe commit a64532a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"os"
"strings"

gin "github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -50,7 +51,15 @@ func Authorization(c *gin.Context) {
}
}
if len(API_KEYS) != 0 && !API_KEYS[c.Request.Header.Get("Authorization")] {
c.JSON(401, gin.H{"error": "Unauthorized"})
if c.Request.Header.Get("Authorization") == "" {
c.JSON(401, gin.H{"error": "No API key provided. Get one at https://discord.gg/9K2BvbXEHT"})
} else if strings.HasPrefix(c.Request.Header.Get("Authorization"), "Bearer sk-") {
c.JSON(401, gin.H{"error": "You tried to use the official API key which is not supported."})
} else if strings.HasPrefix(c.Request.Header.Get("Authorization"), "Bearer eyJhbGciOiJSUzI1NiI") {
return
} else {
c.JSON(401, gin.H{"error": "Invalid API key."})
}
c.Abort()
return
}
Expand Down

0 comments on commit a64532a

Please sign in to comment.