diff --git a/cli/packages/cmd/login.go b/cli/packages/cmd/login.go index 6a1dc23130..c37bdda080 100644 --- a/cli/packages/cmd/login.go +++ b/cli/packages/cmd/login.go @@ -101,6 +101,9 @@ var loginCmd = &cobra.Command{ util.HandleError(err, "Unable to write write to Infisical Config file. Please try again") } + // clear backed up secrets from prev account + util.DeleteBackupSecrets() + color.Green("Nice! You are logged in as: %v", email) }, diff --git a/cli/packages/util/secrets.go b/cli/packages/util/secrets.go index 57b105de34..86f4a5e05a 100644 --- a/cli/packages/util/secrets.go +++ b/cli/packages/util/secrets.go @@ -411,3 +411,16 @@ func ReadBackupSecrets(workspace string, environment string, encryptionKey []byt return plainTextSecrets, nil } + +func DeleteBackupSecrets() error { + secrets_backup_folder_name := "secrets-backup" + + _, fullConfigFileDirPath, err := GetFullConfigFilePath() + if err != nil { + return fmt.Errorf("ReadBackupSecrets: unable to write config file because an error occurred when getting config file path [err=%s]", err) + } + + fullPathToSecretsBackupFolder := fmt.Sprintf("%s/%s", fullConfigFileDirPath, secrets_backup_folder_name) + + return os.RemoveAll(fullPathToSecretsBackupFolder) +}