• Steven's avatar
    fix(web): fix spurious logout on page reload with expired access token · 9ecd7b87
    Steven authored
    Two bugs caused users to be redirected to /auth too frequently:
    
    1. Race condition in Promise.all([initInstance(), initAuth()]):
       initInstance() makes a gRPC request whose auth interceptor calls
       getAccessToken() synchronously. When the access token was expired,
       getAccessToken() eagerly deleted it from localStorage as a "cleanup"
       side-effect. By the time initAuth() ran and checked hasStoredToken(),
       localStorage was already empty, so it skipped the getCurrentUser()
       call and the token refresh cycle entirely — logging the user out even
       when the refresh-token cookie was still valid. Fix: remove the
       localStorage deletion from getAccessToken(); clearAccessToken()
       (called on confirmed auth failure and logout) handles proper cleanup.
    
    2. React Query retry: 1 caused a second refresh+redirect attempt after
       auth failures. The auth interceptor already handles token refresh and
       request retry internally. If it still throws Unauthenticated, the
       redirect is already in flight — a React Query retry only fires another
       failed refresh and a redundant redirectOnAuthFailure() call. Fix: use
       a shouldRetry function that skips retries for Unauthenticated errors
       while keeping the existing once-retry behaviour for other errors.
    9ecd7b87
Name
Last commit
Last update
.github Loading commit data...
cmd/memos Loading commit data...
internal Loading commit data...
plugin Loading commit data...
proto Loading commit data...
scripts Loading commit data...
server Loading commit data...
store Loading commit data...
web Loading commit data...
.dockerignore Loading commit data...
.gitignore Loading commit data...
.golangci.yaml Loading commit data...
AGENTS.md Loading commit data...
CODEOWNERS Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
go.mod Loading commit data...
go.sum Loading commit data...