fix auth bug

This commit is contained in:
Sakurasan
2025-04-17 19:58:46 +08:00
parent a32a9543e2
commit 87778326ea
2 changed files with 2 additions and 1 deletions

View File

@@ -158,6 +158,7 @@ func main() {
}
go func() {
fmt.Println("Starting server at port:", cfg.Port)
// 服务启动
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)

View File

@@ -63,7 +63,7 @@ func AuthLLM(db *gorm.DB) gin.HandlerFunc {
}
auth_token = auth_token[7:]
token := model.Token{}
if err := db.Preload("Users").First(&token, "key = ?", auth_token).Error; err != nil {
if err := db.Preload("User").Where("key = ?", auth_token).First(&token).Error; err != nil {
dto.WrapErrorAsOpenAI(c, http.StatusUnauthorized, "invalid_api_key")
c.Abort()
return