From f4934d06cd52db8c0db0151da381e9d09b37e6cf Mon Sep 17 00:00:00 2001 From: morganelle Date: Fri, 12 Mar 2021 14:13:11 -0800 Subject: [PATCH] add prompt for user to change default tenant after login --- internal/cli/login.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/cli/login.go b/internal/cli/login.go index 3102e6c48..3b1ea5719 100644 --- a/internal/cli/login.go +++ b/internal/cli/login.go @@ -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" ) @@ -62,7 +63,7 @@ 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, @@ -70,4 +71,20 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error { 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 }