Skip to content

Commit

Permalink
Return instructions for users to refresh their credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable committed Oct 23, 2024
1 parent c5c4e72 commit ef73b4a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions private/buf/cmd/buf/command/registry/whoami/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

const (
formatFlagName = "format"

loginCommand = "buf registry login"
)

// NewCommand returns a new Command.
Expand Down Expand Up @@ -94,13 +96,17 @@ func run(
currentUserResponse, err := authnService.GetCurrentUser(ctx, connect.NewRequest(&registryv1alpha1.GetCurrentUserRequest{}))
if err != nil {
if connectErr := new(connect.Error); errors.As(err, &connectErr) && connectErr.Code() == connect.CodeUnauthenticated {
return fmt.Errorf("Not currently logged in for %s", remote)
return fmt.Errorf("Not currently logged in for %s.", remote)
}
return err
}
user := currentUserResponse.Msg.User
if user == nil {
return errors.New("No user found for provided token")
return fmt.Errorf(
`No valid user found for login credentials. Run %q to refresh your credentials. If you have %s environment variable set, ensure that the token is not expired.`,
loginCommand,
bufconnect.TokenEnvKey,
)
}
format, err := bufprint.ParseFormat(flags.Format)
if err != nil {
Expand Down

0 comments on commit ef73b4a

Please sign in to comment.