Skip to content

fix(auth): doctor reads token from current profile#6

Merged
4ier merged 1 commit into4ier:mainfrom
ahnbu:fix/auth-doctor-profile-token
Mar 12, 2026
Merged

fix(auth): doctor reads token from current profile#6
4ier merged 1 commit into4ier:mainfrom
ahnbu:fix/auth-doctor-profile-token

Conversation

@ahnbu
Copy link
Contributor

@ahnbu ahnbu commented Mar 11, 2026

Summary

Fixes #5

notion auth doctor always failed with ✗ Config: no token found even after a successful notion auth login, because it was checking the legacy top-level cfg.Token field — which is cleared by MigrateToProfiles() when the new profile format is used.

Root Cause

// cmd/auth.go — before fix
cfg, err := config.Load()
if err != nil || cfg.Token == "" {   // cfg.Token is "" after profile-based login

auth login stores the token in cfg.Profiles["default"].Token, not cfg.Token. After MigrateToProfiles() runs, the top-level Token field is cleared.

Fix

Resolve the token via GetCurrentProfile() (the existing accessor) when the legacy field is empty, then use that token for both the nil-check and the API client:

cfg, err := config.Load()
profile := cfg.GetCurrentProfile()
token := cfg.Token
if token == "" && profile != nil {
    token = profile.Token
}
if err != nil || token == "" {
    // ...
}
c := client.New(token)

Testing

Before: notion auth loginnotion auth doctor✗ Config: no token found
After: notion auth loginnotion auth doctorAll checks passed ✓

After profile-based login, cfg.Token is empty because MigrateToProfiles
clears it. doctor was only checking the legacy top-level token field,
causing it to always report 'no token found' even after a successful login.

Fixes 4ier#5
@4ier 4ier merged commit 90010ed into 4ier:main Mar 12, 2026
4 checks passed
@4ier
Copy link
Owner

4ier commented Mar 12, 2026

Clean fix, merged! Thanks for tracking down the profile format mismatch. 🎯

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.

auth doctor always fails with 'no token found' after login (profile format mismatch)

2 participants