diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index d0f9cad9..7278284f 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -20,9 +20,6 @@ type LoginAuth struct { Auth } -// assert that LoginAuth implements store.Auth -// var _ store.Auth = (*LoginAuth)(nil) - func NewLoginAuth(authStore AuthStore, oauth OAuth) *LoginAuth { return &LoginAuth{ Auth: *NewAuth(authStore, oauth), diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 5609d53f..90b356e9 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -106,8 +106,12 @@ func NewBrevCommand() *cobra.Command { //nolint:funlen,gocognit,gocyclo // defin OauthTokenEndpoint: "https://brevdev.us.auth0.com/oauth/token", } - email := auth.GetEmailFromToken(tokens.AccessToken) - shouldPromptEmail := true + var email string + shouldPromptEmail := false + if tokens != nil && tokens.AccessToken != "" { + email = auth.GetEmailFromToken(tokens.AccessToken) + shouldPromptEmail = true + } if emailFlag != "" { email = emailFlag shouldPromptEmail = false diff --git a/pkg/store/authtoken.go b/pkg/store/authtoken.go index c7a19cbb..584dd4c8 100644 --- a/pkg/store/authtoken.go +++ b/pkg/store/authtoken.go @@ -77,15 +77,6 @@ func (f FileStore) GetAuthTokens() (*entity.AuthTokens, error) { return &token, nil } -// func (f FileStore) getBrevCredentialsFile() (*string, error) { -// home, err := f.UserHomeDir() -// if err != nil { -// return nil, breverrors.WrapAndTrace(err) -// } -// brevCredentialsFile := path.Join(home, brevDirectory, brevCredentialsFile) -// return &brevCredentialsFile, nil -// } - func (f FileStore) GetCurrentWorkspaceServiceToken() (string, error) { saTokenFilePath := getServiceTokenFilePath() // safely check if file exists diff --git a/pkg/store/organization.go b/pkg/store/organization.go index dedea1a8..8f7c25b0 100644 --- a/pkg/store/organization.go +++ b/pkg/store/organization.go @@ -2,6 +2,7 @@ package store import ( "fmt" + "strings" "github.com/brevdev/brev-cli/pkg/entity" breverrors "github.com/brevdev/brev-cli/pkg/errors" @@ -31,7 +32,7 @@ func (f FileStore) ClearDefaultOrganization() error { } path := files.GetActiveOrgsPath(home) err = files.DeleteFile(f.fs, path) - if err != nil { + if err != nil && !strings.Contains(err.Error(), "no such file or directory") { return breverrors.WrapAndTrace(err) } return nil