Skip to content

Commit

Permalink
Merge pull request #843 from planetscale/better-auth-check
Browse files Browse the repository at this point in the history
Add an API call to the auth check
  • Loading branch information
mscoutermarsh authored Mar 29, 2024
2 parents ca586ff + 7d5648c commit 4946835
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions internal/cmd/auth/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@ func CheckCmd(ch *cmdutil.Helper) *cobra.Command {
Args: cobra.NoArgs,
Short: "Check if you are authenticated",
RunE: func(cmd *cobra.Command, args []string) error {
errorMessage := "You are not authenticated. Please run `pscale auth login` to authenticate."

if ch.Config.AccessToken == "" {
return &cmdutil.Error{
Msg: "You are not authenticated. Please run `pscale auth login` to authenticate.",
Msg: errorMessage,
ExitCode: cmdutil.ActionRequestedExitCode,
}
} else {
ch.Printer.Printf("You are authenticated.")
return nil
ctx := cmd.Context()
client, err := ch.Client()
if err != nil {
return err
}

_, err = client.Organizations.List(ctx)
if err != nil {
return &cmdutil.Error{
Msg: errorMessage,
ExitCode: cmdutil.ActionRequestedExitCode,
}
} else {
ch.Printer.Printf("You are authenticated.")
return nil
}
}
},
}
Expand Down

0 comments on commit 4946835

Please sign in to comment.