diff --git a/auth/auth.go b/auth/auth.go index 16fb126..87f3017 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -27,23 +27,25 @@ type Client struct { state string } -func New(cfg *config.Config) *Client { - auth := spotifyauth.New( - spotifyauth.WithClientID(cfg.GetClientValue(config.SpotifyIDKey)), - spotifyauth.WithClientSecret(cfg.GetClientValue(config.SpotifySecretKey)), - spotifyauth.WithRedirectURL(redirectURI), - spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), - ) - +func NewClient(cfg *config.Config) *Client { return &Client{ SpotifyChannel: make(chan *spotify.Client, 1), cfg: cfg, - auth: auth, + auth: NewAuth(cfg), server: &http.Server{Addr: fmt.Sprintf(":%s", authPort)}, state: uuid.New().String(), } } +func NewAuth(cfg *config.Config) *spotifyauth.Authenticator { + return spotifyauth.New( + spotifyauth.WithClientID(cfg.GetClientValue(config.SpotifyIDKey)), + spotifyauth.WithClientSecret(cfg.GetClientValue(config.SpotifySecretKey)), + spotifyauth.WithRedirectURL(redirectURI), + spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), + ) +} + func (a *Client) Authorize() { http.HandleFunc("/callback", a.completeAuth) go func() { diff --git a/ui/greeting/update.go b/ui/greeting/update.go index c8ffd7e..66b555e 100644 --- a/ui/greeting/update.go +++ b/ui/greeting/update.go @@ -113,7 +113,7 @@ func (m *Model) setClientConfig(key config.ConfKey, value any) tea.Cmd { } func (m *Model) Authorize() tea.Msg { - authClient := auth.New(m.cfg) + authClient := auth.NewClient(m.cfg) authClient.Authorize()