Skip to content

fix(auth): update config file when switching default grant#14

Merged
qasim-nylas merged 1 commit intonylas:mainfrom
mqasimca:fix/auth-switch-update-config-file
Feb 3, 2026
Merged

fix(auth): update config file when switching default grant#14
qasim-nylas merged 1 commit intonylas:mainfrom
mqasimca:fix/auth-switch-update-config-file

Conversation

@mqasimca
Copy link
Contributor

@mqasimca mqasimca commented Feb 3, 2026

Summary

  • Fixed a bug where nylas auth switch only updated the default grant in the keyring but not in the config file (~/.config/nylas/config.yaml)
  • The config file's default_grant field remained stale after switching accounts
  • Now both SwitchGrant and SwitchGrantByEmail update the keyring (authoritative source) and the config file

Problem

When running nylas auth switch <email>:

  1. nylas auth list showed the correct default (reads from keyring) ✓
  2. ~/.config/nylas/config.yaml still showed the old default_grant value ✗

This inconsistency caused confusion when inspecting the config file directly.

Solution

Added a setDefaultGrant() helper method in GrantService that updates both:

  1. Keyring via grantStore.SetDefaultGrant() - authoritative source
  2. Config file via config.Load() → set DefaultGrantconfig.Save()

Config save errors are non-fatal since the keyring is the source of truth.

Changes

  • internal/app/auth/grants.go: Added setDefaultGrant() helper, updated SwitchGrant() and SwitchGrantByEmail() to use it
  • internal/app/auth/grants_test.go: Added comprehensive unit tests for GrantService switch operations

Test plan

  • Unit tests pass (go test ./internal/app/auth/...)
  • make ci passes (fmt, vet, lint, tests, security, vuln)
  • Manual test: nylas auth switch <email> updates both keyring and config file

Previously, `nylas auth switch` only updated the default grant in the
keyring but not in the config file (~/.config/nylas/config.yaml). This
caused the config file to show stale default_grant values.

Now both SwitchGrant and SwitchGrantByEmail update the keyring
(authoritative) and the config file. Config save errors are non-fatal
since the keyring is the source of truth.

Added unit tests for GrantService switch operations.
@qasim-nylas qasim-nylas merged commit d2d5972 into nylas:main Feb 3, 2026
2 checks passed
@mqasimca mqasimca deleted the fix/auth-switch-update-config-file branch February 4, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants