Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,13 @@ func CheckAuthHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"authenticated": authenticated})
}

// AuthRequired checks if API authentication is configured
// AuthRequired checks if single-user authentication is configured, by either
// an API key or a username/password pair.
func AuthRequired() bool {
envApiKey := config.Get("API_KEY", "")
return envApiKey != ""
envUsername := config.Get("AUTH_USERNAME", "")
envPassword := config.Get("AUTH_PASSWORD", "")
return envApiKey != "" || (envUsername != "" && envPassword != "")
}

// CheckSingleUserPaired checks if rmapi.conf exists for single-user mode
Expand Down
8 changes: 1 addition & 7 deletions internal/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/rmitchellscott/aviary/internal/config"
"github.com/rmitchellscott/aviary/internal/database"
)

Expand Down Expand Up @@ -84,12 +83,7 @@ func OptionalAuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
if !database.IsMultiUserMode() {
// In single-user mode, skip auth if not configured
envApiKey := config.Get("API_KEY", "")
envUsername := config.Get("AUTH_USERNAME", "")
envPassword := config.Get("AUTH_PASSWORD", "")
authConfigured := envApiKey != "" || (envUsername != "" && envPassword != "")

if !authConfigured {
if !AuthRequired() {
c.Next()
return
}
Expand Down
Loading