Skip to content

Commit f6a66bc

Browse files
committed
fix: aggregate email and label params in CLI auth callback
1 parent e7616fe commit f6a66bc

File tree

3 files changed

+32
-52
lines changed

3 files changed

+32
-52
lines changed

cmd/auth.go

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ This secure authentication flow:
5454
fmt.Println("🔐 Authenticating with Vapi...")
5555
fmt.Println()
5656

57-
// Read optional flags for labeling
58-
labelFlag, _ := cmd.Flags().GetString("label")
59-
emailFlag, _ := cmd.Flags().GetString("email") // alias, for backward-compat
57+
// Read optional flags for overrides
58+
emailFlag, _ := cmd.Flags().GetString("email")
6059
orgFlag, _ := cmd.Flags().GetString("org")
6160

6261
// Start the browser-based authentication flow
@@ -65,26 +64,23 @@ This secure authentication flow:
6564
return err
6665
}
6766

68-
// Optionally override label/org with flags if provided
67+
// Optionally override email/org with flags if provided
6968
cfg, err := config.LoadConfig()
7069
if err == nil && cfg.ActiveAccount != "" {
7170
acc := cfg.Accounts[cfg.ActiveAccount]
7271
changed := false
7372

7473
// Apply flags if provided
75-
if labelFlag != "" {
76-
acc.Label = labelFlag
77-
changed = true
78-
} else if emailFlag != "" { // backward-compat: set label from email flag
79-
acc.Label = emailFlag
74+
if emailFlag != "" {
75+
acc.Email = emailFlag
8076
changed = true
8177
}
8278
if orgFlag != "" {
8379
acc.Organization = orgFlag
8480
changed = true
8581
}
8682

87-
// No more interactive prompt - the dashboard now provides label/email
83+
// No interactive prompt - the dashboard now provides email
8884

8985
// Persist if any changes
9086
if changed {
@@ -208,10 +204,7 @@ which account you're currently using.`,
208204
if account.Organization != "" {
209205
fmt.Printf(" - %s", account.Organization)
210206
}
211-
// Prefer Label; fallback to Email if present
212-
if account.Label != "" {
213-
fmt.Printf(" <%s>", account.Label)
214-
} else if account.Email != "" {
207+
if account.Email != "" {
215208
fmt.Printf(" <%s>", account.Email)
216209
}
217210
if account.LoginTime != "" {
@@ -311,10 +304,7 @@ This is useful when working with multiple organizations or environments.`,
311304
if account.Organization != "" {
312305
displayName = fmt.Sprintf("%s (%s)", accountName, account.Organization)
313306
}
314-
// Prefer Label; fallback to Email if present
315-
if account.Label != "" {
316-
displayName = fmt.Sprintf("%s <%s>", displayName, account.Label)
317-
} else if account.Email != "" {
307+
if account.Email != "" {
318308
displayName = fmt.Sprintf("%s <%s>", displayName, account.Email)
319309
}
320310
if accountName == cfg.ActiveAccount {
@@ -359,9 +349,7 @@ This is useful when working with multiple organizations or environments.`,
359349
if account.Organization != "" {
360350
fmt.Printf(" - %s", account.Organization)
361351
}
362-
if account.Label != "" {
363-
fmt.Printf(" <%s>", account.Label)
364-
} else if account.Email != "" {
352+
if account.Email != "" {
365353
fmt.Printf(" <%s>", account.Email)
366354
}
367355
fmt.Println()
@@ -382,9 +370,7 @@ This is useful when working with multiple organizations or environments.`,
382370
if account.Organization != "" {
383371
fmt.Printf(" (%s)", account.Organization)
384372
}
385-
if account.Label != "" {
386-
fmt.Printf(" <%s>", account.Label)
387-
} else if account.Email != "" {
373+
if account.Email != "" {
388374
fmt.Printf(" <%s>", account.Email)
389375
}
390376
fmt.Println()
@@ -510,7 +496,6 @@ func init() {
510496
rootCmd.AddCommand(authCmd)
511497

512498
// Flags for login labeling
513-
authLoginCmd.Flags().String("label", "", "Override the label for this account (default: your email from dashboard)")
514-
authLoginCmd.Flags().String("email", "", "Alias for --label")
499+
authLoginCmd.Flags().String("email", "", "Override the email for this account (default: your email from dashboard)")
515500
authLoginCmd.Flags().String("org", "", "Override the organization name for this account")
516501
}

pkg/auth/auth.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type AuthManager struct {
4040
authError chan error
4141
orgName string
4242
orgID string
43-
label string
43+
email string
4444
}
4545

4646
func NewAuthManager() *AuthManager {
@@ -179,13 +179,11 @@ func (a *AuthManager) createCallbackHandler(expectedState string) http.Handler {
179179
a.orgID = orgID
180180
}
181181

182-
// Optional label (fallback to email if provided)
183-
if label := r.URL.Query().Get("label"); label != "" {
184-
a.label = label
185-
} else if email := r.URL.Query().Get("email"); email != "" { // backward-compat
186-
a.label = email
187-
} else if email := r.URL.Query().Get("user_email"); email != "" { // backward-compat
188-
a.label = email
182+
// Optional email
183+
if email := r.URL.Query().Get("email"); email != "" {
184+
a.email = email
185+
} else if email := r.URL.Query().Get("user_email"); email != "" {
186+
a.email = email
189187
}
190188

191189
// Send success response
@@ -361,7 +359,7 @@ func LoginWithAccountName(accountName string) error {
361359
OrgID: authManager.orgID,
362360
Environment: cfg.GetEnvironment(),
363361
LoginTime: time.Now().Format(time.RFC3339),
364-
Label: firstNonEmpty(authManager.label, existing.Label, existing.Email),
362+
Email: firstNonEmpty(authManager.email, existing.Email),
365363
}
366364
cfg.ActiveAccount = existingName
367365

@@ -371,8 +369,8 @@ func LoginWithAccountName(accountName string) error {
371369

372370
fmt.Printf("\n✅ Re-authenticated existing account '%s'!\n", existingName)
373371
fmt.Printf("Organization: %s\n", authManager.orgName)
374-
if authManager.label != "" {
375-
fmt.Printf("Label: %s\n", authManager.label)
372+
if authManager.email != "" {
373+
fmt.Printf("Email: %s\n", authManager.email)
376374
}
377375
if len(cfg.Accounts) > 1 {
378376
fmt.Println("💡 Use 'vapi auth switch' to switch between accounts")
@@ -393,7 +391,7 @@ func LoginWithAccountName(accountName string) error {
393391
OrgID: authManager.orgID,
394392
Environment: cfg.GetEnvironment(),
395393
LoginTime: time.Now().Format(time.RFC3339),
396-
Label: firstNonEmpty(authManager.label, existing.Label, existing.Email),
394+
Email: firstNonEmpty(authManager.email, existing.Email),
397395
}
398396
cfg.ActiveAccount = existingName
399397

@@ -403,8 +401,8 @@ func LoginWithAccountName(accountName string) error {
403401

404402
fmt.Printf("\n✅ Re-authenticated existing account '%s'!\n", existingName)
405403
fmt.Printf("Organization: %s\n", authManager.orgName)
406-
if authManager.label != "" {
407-
fmt.Printf("Label: %s\n", authManager.label)
404+
if authManager.email != "" {
405+
fmt.Printf("Email: %s\n", authManager.email)
408406
}
409407
if len(cfg.Accounts) > 1 {
410408
fmt.Println("💡 Use 'vapi auth switch' to switch between accounts")
@@ -430,7 +428,7 @@ func LoginWithAccountName(accountName string) error {
430428
OrgID: authManager.orgID,
431429
Environment: cfg.GetEnvironment(),
432430
LoginTime: time.Now().Format(time.RFC3339),
433-
Label: firstNonEmpty(authManager.label, existing.Label, existing.Email),
431+
Email: firstNonEmpty(authManager.email, existing.Email),
434432
}
435433
// Set as active account
436434
cfg.ActiveAccount = existingName
@@ -443,8 +441,8 @@ func LoginWithAccountName(accountName string) error {
443441
if orgName != "" {
444442
fmt.Printf("Organization: %s\n", orgName)
445443
}
446-
if authManager.label != "" {
447-
fmt.Printf("Label: %s\n", authManager.label)
444+
if authManager.email != "" {
445+
fmt.Printf("Email: %s\n", authManager.email)
448446
}
449447
if len(cfg.Accounts) > 1 {
450448
fmt.Println("💡 Use 'vapi auth switch' to switch between accounts")
@@ -459,7 +457,7 @@ func LoginWithAccountName(accountName string) error {
459457
}
460458

461459
// Add as new account (supports multiple accounts). Use org info if we captured it.
462-
cfg.AddAccount(accountName, apiKey, authManager.orgName, authManager.orgID, authManager.label)
460+
cfg.AddAccount(accountName, apiKey, authManager.orgName, authManager.orgID, authManager.email)
463461

464462
// For backward compatibility, also set legacy APIKey field if it's the first account
465463
if len(cfg.Accounts) == 1 {
@@ -474,8 +472,8 @@ func LoginWithAccountName(accountName string) error {
474472
if authManager.orgName != "" {
475473
fmt.Printf("Organization: %s\n", authManager.orgName)
476474
}
477-
if authManager.label != "" {
478-
fmt.Printf("Label: %s\n", authManager.label)
475+
if authManager.email != "" {
476+
fmt.Printf("Email: %s\n", authManager.email)
479477
}
480478
if len(cfg.Accounts) > 1 {
481479
fmt.Println("💡 Use 'vapi auth switch' to switch between accounts")

pkg/config/config.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ type Account struct {
4747
OrgID string `mapstructure:"org_id,omitempty"` // Organization ID for reliable deduplication
4848
Environment string `mapstructure:"environment,omitempty"` // Per-account environment override
4949
LoginTime string `mapstructure:"logintime,omitempty"` // When this account was last authenticated
50-
// Preferred: user-defined label for the account (e.g., email, purpose, alias)
51-
Label string `mapstructure:"label,omitempty"`
52-
// Backward-compat: previously stored as email; still read if present
53-
Email string `mapstructure:"email,omitempty"`
50+
Email string `mapstructure:"email,omitempty"` // User email if available
5451
}
5552

5653
// Environment configuration
@@ -258,7 +255,7 @@ func (c *Config) GetActiveAccount() *Account {
258255
}
259256

260257
// AddAccount adds a new account or updates an existing one
261-
func (c *Config) AddAccount(accountKey, apiKey, organization, orgID, label string) {
258+
func (c *Config) AddAccount(accountKey, apiKey, organization, orgID, email string) {
262259
if c.Accounts == nil {
263260
c.Accounts = make(map[string]Account)
264261
}
@@ -269,7 +266,7 @@ func (c *Config) AddAccount(accountKey, apiKey, organization, orgID, label strin
269266
OrgID: orgID,
270267
Environment: c.Environment, // Use current environment as default
271268
LoginTime: time.Now().Format(time.RFC3339),
272-
Label: label,
269+
Email: email,
273270
}
274271

275272
// Set as active account if it's the first one or no active account is set

0 commit comments

Comments
 (0)