Skip to content

Commit

Permalink
refactor: add method IsAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent 5a75e6d commit aa155e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (s *Server) unauthenticatedOnly() gin.HandlerFunc {
return func(c *gin.Context) {
if s.spoty.Client != nil {
if s.spoty.IsAuth() {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "you are already authenticated"})
return
}
Expand All @@ -19,7 +19,7 @@ func (s *Server) unauthenticatedOnly() gin.HandlerFunc {

func (s *Server) authenticatedOnly() gin.HandlerFunc {
return func(c *gin.Context) {
if s.spoty.Client == nil {
if !s.spoty.IsAuth() {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "you must be authenticated to access this endpoint"})
return
}
Expand Down
4 changes: 4 additions & 0 deletions spoty/spoty.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func New(clientID, clientSecret, host string, port int, cache *cache.Cache) (*Sp
}, nil
}

func (s *Spoty) IsAuth() bool {
return s.Client != nil
}

func (s *Spoty) IsPlaying() bool {
state, err := s.Client.PlayerState()
if err != nil {
Expand Down

0 comments on commit aa155e4

Please sign in to comment.