@@ -106,6 +106,13 @@ func doDaemonLogin(ctx context.Context, cmd *cobra.Command, providedSetupKey str
106106 Username : & username ,
107107 }
108108
109+ profileState , err := pm .GetProfileState (activeProf .Name )
110+ if err != nil {
111+ log .Debugf ("failed to get profile state for login hint: %v" , err )
112+ } else if profileState .Email != "" {
113+ loginRequest .Hint = & profileState .Email
114+ }
115+
109116 if rootCmd .PersistentFlags ().Changed (preSharedKeyFlag ) {
110117 loginRequest .OptionalPreSharedKey = & preSharedKey
111118 }
@@ -241,7 +248,7 @@ func doForegroundLogin(ctx context.Context, cmd *cobra.Command, setupKey string,
241248 return fmt .Errorf ("read config file %s: %v" , configFilePath , err )
242249 }
243250
244- err = foregroundLogin (ctx , cmd , config , setupKey )
251+ err = foregroundLogin (ctx , cmd , config , setupKey , activeProf . Name )
245252 if err != nil {
246253 return fmt .Errorf ("foreground login failed: %v" , err )
247254 }
@@ -269,7 +276,7 @@ func handleSSOLogin(ctx context.Context, cmd *cobra.Command, loginResp *proto.Lo
269276 return nil
270277}
271278
272- func foregroundLogin (ctx context.Context , cmd * cobra.Command , config * profilemanager.Config , setupKey string ) error {
279+ func foregroundLogin (ctx context.Context , cmd * cobra.Command , config * profilemanager.Config , setupKey , profileName string ) error {
273280 needsLogin := false
274281
275282 err := WithBackOff (func () error {
@@ -286,7 +293,7 @@ func foregroundLogin(ctx context.Context, cmd *cobra.Command, config *profileman
286293
287294 jwtToken := ""
288295 if setupKey == "" && needsLogin {
289- tokenInfo , err := foregroundGetTokenInfo (ctx , cmd , config )
296+ tokenInfo , err := foregroundGetTokenInfo (ctx , cmd , config , profileName )
290297 if err != nil {
291298 return fmt .Errorf ("interactive sso login failed: %v" , err )
292299 }
@@ -315,8 +322,17 @@ func foregroundLogin(ctx context.Context, cmd *cobra.Command, config *profileman
315322 return nil
316323}
317324
318- func foregroundGetTokenInfo (ctx context.Context , cmd * cobra.Command , config * profilemanager.Config ) (* auth.TokenInfo , error ) {
319- oAuthFlow , err := auth .NewOAuthFlow (ctx , config , isUnixRunningDesktop ())
325+ func foregroundGetTokenInfo (ctx context.Context , cmd * cobra.Command , config * profilemanager.Config , profileName string ) (* auth.TokenInfo , error ) {
326+ hint := ""
327+ pm := profilemanager .NewProfileManager ()
328+ profileState , err := pm .GetProfileState (profileName )
329+ if err != nil {
330+ log .Debugf ("failed to get profile state for login hint: %v" , err )
331+ } else if profileState .Email != "" {
332+ hint = profileState .Email
333+ }
334+
335+ oAuthFlow , err := auth .NewOAuthFlow (ctx , config , isUnixRunningDesktop (), hint )
320336 if err != nil {
321337 return nil , err
322338 }
0 commit comments