diff --git a/internal/command/login.go b/internal/command/login.go index 52e2a0f..f4295f5 100644 --- a/internal/command/login.go +++ b/internal/command/login.go @@ -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 { @@ -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 }