Skip to content

Commit

Permalink
feat: Login api check
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldimbarre committed Jan 31, 2024
1 parent 265209d commit 0faf1de
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/erikgeiser/promptkit/textinput"
"github.com/spf13/cobra"
"github.com/squarecloudofc/cli/internal/cli"
"github.com/squarecloudofc/cli/internal/rest"
)

func NewLoginCommand(squareCli *cli.SquareCli) *cobra.Command {
Expand Down Expand Up @@ -35,10 +36,23 @@ func runLoginCommand(squareCli *cli.SquareCli) RunEFunc {
return
}

restClient := rest.NewClient(token)

self, err := restClient.SelfUser()

if err != nil {
return
}

if self == nil || self.User.Tag == "" {
fmt.Fprintf(squareCli.Out(), "No user associated for this Square Cloud Token\n")
return
}

squareCli.Config.AuthToken = token
squareCli.Config.Save()

fmt.Fprintln(squareCli.Out(), "Your API Token has successfuly changed")
fmt.Fprintf(squareCli.Out(), "Your API Token has successfuly changed! You are now logged in a %s\n", self.User.Tag)
fmt.Fprintln(squareCli.Out(), "\nWith great power comes great responsibility!")
return
}
Expand Down

0 comments on commit 0faf1de

Please sign in to comment.