Skip to content

Commit

Permalink
Merge pull request #156 from auth0/set-default-tenant
Browse files Browse the repository at this point in the history
[CLI-68] add prompt for user to change default tenant after login
  • Loading branch information
Widcket authored Mar 13, 2021
2 parents 36abf07 + 51e0982 commit 732b4b6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth"
"github.com/auth0/auth0-cli/internal/open"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -62,12 +63,28 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error {
cli.renderer.Infof("Successfully logged in.")
cli.renderer.Infof("Tenant: %s\n", res.Tenant)

return cli.addTenant(tenant{
err = cli.addTenant(tenant{
Name: res.Tenant,
Domain: res.Domain,
AccessToken: res.AccessToken,
ExpiresAt: time.Now().Add(
time.Duration(res.ExpiresIn) * time.Second,
),
})
if err != nil {
return fmt.Errorf("Unexpected error adding tenant to config: %w", err)
}

if cli.config.DefaultTenant != res.Tenant {
promptText := fmt.Sprintf("Your default tenant is %s. Do you want to change it to %s?", cli.config.DefaultTenant, res.Tenant)
if confirmed := prompt.Confirm(promptText); !confirmed {
return nil
}
cli.config.DefaultTenant = res.Tenant
if err := cli.persistConfig(); err != nil {
return fmt.Errorf("An error occurred while setting the default tenant: %w", err)
}
}

return nil
}

0 comments on commit 732b4b6

Please sign in to comment.