Skip to content

Commit

Permalink
add NewAuth func to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Aug 10, 2023
1 parent a5a3024 commit 962fc67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion ui/greeting/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 962fc67

Please sign in to comment.