Skip to content

Commit

Permalink
show user's name on login
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstrauch committed Jun 26, 2021
1 parent 946ccac commit 2670ade
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/blang/semver v3.5.1+incompatible
github.com/brianstrauch/spotify v0.2.0
github.com/brianstrauch/spotify v0.3.0
github.com/pkg/browser v0.0.0-20210606212950-a7b7a6107d32
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/spf13/cobra v1.1.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/brianstrauch/spotify v0.2.0 h1:CoKjSY/JqFOfMw3aD4YyC0YN49HPrn4vax4nLk0TBwo=
github.com/brianstrauch/spotify v0.2.0/go.mod h1:sImRT74obai+LNgFVxr+qNVq2yt5KEfvNxz6ZDfYWaA=
github.com/brianstrauch/spotify v0.3.0 h1:09iAmmn3pncnCdHOghiBH2r619HkWt35j59yEBXwUt0=
github.com/brianstrauch/spotify v0.3.0/go.mod h1:sImRT74obai+LNgFVxr+qNVq2yt5KEfvNxz6ZDfYWaA=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
16 changes: 13 additions & 3 deletions internal/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewCommand() *cobra.Command {
Use: "login",
Short: "Log in to Spotify.",
RunE: func(cmd *cobra.Command, _ []string) error {
token, err := authorize()
token, err := login()
if err != nil {
return err
}
Expand All @@ -38,13 +38,23 @@ func NewCommand() *cobra.Command {
return err
}

cmd.Println("Success!")
api, err := internal.Authenticate()
if err != nil {
return err
}

user, err := api.GetUserProfile()
if err != nil {
return err
}

cmd.Printf("Logged in as %s.\n", user.DisplayName)
return nil
},
}
}

func authorize() (*spotify.Token, error) {
func login() (*spotify.Token, error) {
// 1. Create the code verifier and challenge
verifier, challenge, err := spotify.CreateVerifierAndChallenge()
if err != nil {
Expand Down

0 comments on commit 2670ade

Please sign in to comment.