Skip to content

fix: auto re-authenticate when stored GitHub token returns 401#202

Open
xuangong wants to merge 1 commit intoericc-ch:masterfrom
xuangong:fix/auto-reauth-on-401
Open

fix: auto re-authenticate when stored GitHub token returns 401#202
xuangong wants to merge 1 commit intoericc-ch:masterfrom
xuangong:fix/auto-reauth-on-401

Conversation

@xuangong
Copy link

Problem

When the stored GitHub token becomes invalid (expired or revoked), calling getGitHubUser() during startup returns 401 Bad Credentials. The error propagates up and crashes the server, requiring the user to manually delete the token file and restart.

Solution

Catch the 401 error from logUser() in setupGitHubToken(), automatically clear the invalid token (both from state and the token file), and fall through to the device code authentication flow so the user can re-authenticate seamlessly.

Changes

  • src/lib/token.ts: Wrap logUser() in a try-catch; on 401, clear the stored token and proceed to re-auth instead of crashing.

When the stored GitHub token becomes invalid (expired or revoked),
the API call to verify the user returns 401 Bad Credentials. Previously
this caused the server to crash with an unhandled error.

Now the invalid token is automatically cleared and the device code
authentication flow is triggered, so the user can re-authenticate
without manually deleting the token file.
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.

1 participant