Skip to content

Commit

Permalink
Fix: Do not save duplicate domains
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHougaard committed Aug 26, 2024
1 parent 7a2f021 commit 1f24d02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/packages/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,14 @@ func askForDomain() error {
config.INFISICAL_LOGIN_URL = fmt.Sprintf("%s/login", domain)

// Write the new domain to the config file, to allow the user to select it in the future if needed
infisicalConfig.Domains = append(infisicalConfig.Domains, domain)
err = util.WriteConfigFile(&infisicalConfig)
// First check if infiscialConfig.Domains already includes the domain, if it does, do not add it again
if !util.ArrayContains(infisicalConfig.Domains, domain) {
infisicalConfig.Domains = append(infisicalConfig.Domains, domain)
err = util.WriteConfigFile(&infisicalConfig)

if err != nil {
return fmt.Errorf("askForDomain: unable to write domains to config file because [err=%s]", err)
if err != nil {
return fmt.Errorf("askForDomain: unable to write domains to config file because [err=%s]", err)
}
}

return nil
Expand Down
9 changes: 9 additions & 0 deletions cli/packages/util/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,12 @@ func GenerateRandomString(length int) string {
}
return string(b)
}

func ArrayContains(arr []string, val string) bool {
for _, item := range arr {
if item == val {
return true
}
}
return false
}

0 comments on commit 1f24d02

Please sign in to comment.