Skip to content

Commit

Permalink
add prompt for user to change default tenant after login
Browse files Browse the repository at this point in the history
  • Loading branch information
morganelle committed Mar 12, 2021
1 parent c95e71a commit f4934d0
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("Change the default tenant to %s?", 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 f4934d0

Please sign in to comment.