Skip to content

Conversation

@kah-seng
Copy link
Member

@kah-seng kah-seng commented Feb 5, 2026

1. Local Storage Not Updated

Access tokens and refresh tokens are only saved to local storage on login, subsequent token refreshes do not update local storage.

Example: User refreshes to a new token and exits Overleaf, the next time he re-opens PaperDebugger, it uses the old refresh token.

Proposed solution: Update authStore whenever tokens are set.


2. Race Conditions When Refreshing

PaperDebugger often calls multiple endpoints at the same time, which results in a race condition if the token needs to be refreshed.

Example: v2/chats/models and v2/chats/conversations are called at the same time, and the access token needs refreshing, the refresh endpoint is called twice. In some occasions, the frontend uses the 2nd refresh token received which differs from the one stored in the backend. This can be easily reproduced by setting the JWT expiration in the backend to a very short time.

Proposed solution: Use a promise for refresh().



Unsure if this fixes the exact problem in #110

@kah-seng kah-seng linked an issue Feb 5, 2026 that may be closed by this pull request
Copy link
Member

@4ndrelim 4ndrelim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was investigating the bug too but saw you raised a PR before i did anything. So left some comments based on my udnerstanding. Seems like the right approach! Ill try to simulate some possible set-ups and test with ur fix.

@kah-seng kah-seng marked this pull request as ready for review February 6, 2026 11:49
Copy link
Member

@4ndrelim 4ndrelim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. This fix should resolve most of the 401 error bugs.

@4ndrelim 4ndrelim merged commit 2ae1791 into main Feb 7, 2026
1 check passed
@4ndrelim 4ndrelim deleted the fix/tokens branch February 7, 2026 17:19
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.

[BUG] Token expiration occurs more frequently than expected

2 participants