@@ -26,7 +26,7 @@ var loginCmd = &cobra.Command{
2626}
2727
2828func runLogin (cobraCmd * cobra.Command ) error {
29- if err := doLogin (cobraCmd ); err != nil {
29+ if err := doLogin (cobraCmd , true ); err != nil {
3030 return err
3131 }
3232 printSuccessMessage (cobraCmd )
@@ -35,7 +35,7 @@ func runLogin(cobraCmd *cobra.Command) error {
3535
3636// doLogin performs the core login flow: browser auth, token storage, and org selection.
3737// Used by both runLogin and RunLoginForLink.
38- func doLogin (cobraCmd * cobra.Command ) error {
38+ func doLogin (cobraCmd * cobra.Command , selectOrg bool ) error {
3939 // Get the API client (no token yet for login flow)
4040 apiClient := singletons .GetAPIClient ()
4141 startResp , err := apiClient .StartLogin ()
@@ -58,26 +58,28 @@ func doLogin(cobraCmd *cobra.Command) error {
5858 return clierrors .WrapError ("failed to store token" , err )
5959 }
6060
61- // Fetch organizations (token will be fetched automatically)
62- orgsResp , err := apiClient .GetOrganizations ()
63- if err != nil {
64- return clierrors .WrapError ("failed to fetch organizations" , err )
65- }
66-
67- // Let user select default organization
68- if len (orgsResp .Organizations ) > 0 {
69- selectedOrg , err := SelectOrganization (cobraCmd , orgsResp .Organizations )
61+ if selectOrg {
62+ // Fetch organizations (token will be fetched automatically)
63+ orgsResp , err := apiClient .GetOrganizations ()
7064 if err != nil {
71- return clierrors .WrapError ("failed to select organization " , err )
65+ return clierrors .WrapError ("failed to fetch organizations " , err )
7266 }
7367
74- if err := mjrToken .StoreDefaultOrg (selectedOrg .ID , selectedOrg .Name ); err != nil {
75- return clierrors .WrapError ("failed to store default organization" , err )
76- }
68+ // Let user select default organization
69+ if len (orgsResp .Organizations ) > 0 {
70+ selectedOrg , err := SelectOrganization (cobraCmd , orgsResp .Organizations )
71+ if err != nil {
72+ return clierrors .WrapError ("failed to select organization" , err )
73+ }
74+
75+ if err := mjrToken .StoreDefaultOrg (selectedOrg .ID , selectedOrg .Name ); err != nil {
76+ return clierrors .WrapError ("failed to store default organization" , err )
77+ }
7778
78- cobraCmd .Printf ("Default organization set to: %s\n " , selectedOrg .Name )
79- } else {
80- return clierrors .ErrorNoOrganizationsAvailable
79+ cobraCmd .Printf ("Default organization set to: %s\n " , selectedOrg .Name )
80+ } else {
81+ return clierrors .ErrorNoOrganizationsAvailable
82+ }
8183 }
8284
8385 return nil
@@ -165,7 +167,7 @@ func SelectOrganization(cobraCmd *cobra.Command, orgs []apiClient.Organization)
165167// RunLoginForLink is an exported function that runs the login flow for the link command.
166168// It's a simplified version that doesn't print the full success message.
167169func RunLoginForLink (cobraCmd * cobra.Command ) error {
168- if err := doLogin (cobraCmd ); err != nil {
170+ if err := doLogin (cobraCmd , false ); err != nil {
169171 return err
170172 }
171173 cobraCmd .Println ("✓ Successfully authenticated!" )
0 commit comments