diff --git a/internal/cli/auth/login.go b/internal/cli/auth/login.go index 2eed5759a2..7f790550b0 100644 --- a/internal/cli/auth/login.go +++ b/internal/cli/auth/login.go @@ -16,6 +16,7 @@ package auth import ( "context" + "errors" "fmt" "os" "time" @@ -56,6 +57,11 @@ const ( LogoutToLoginAccountMsg = `run "atlas auth logout" first if you want to login with another Atlas account on the same Atlas CLI profile` ) +var ( + ErrProjectIDNotFound = errors.New("you don't have access to this or it doesn't exist") + ErrOrgIDNotFound = errors.New("you don't have access to this organization ID or it doesn't exist") +) + type LoginOpts struct { cli.DefaultSetterOpts AccessToken string @@ -189,6 +195,14 @@ func (opts *LoginOpts) setUpProfile(ctx context.Context) error { // Only make references to profile if user was asked about org or projects if opts.AskedOrgsOrProjects && opts.ProjectID != "" && opts.OrgID != "" { + if !opts.ProjectExists(config.ProjectID()) { + return ErrProjectIDNotFound + } + + if !opts.OrgExists(config.OrgID()) { + return ErrOrgIDNotFound + } + _, _ = fmt.Fprint(opts.OutWriter, "\nYour profile is now configured.\n") _, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", config.BinName()) }