• Steven's avatar
    fix: prevent 401 errors on window focus when token expires · 81ef53b3
    Steven authored
    Fixes #5589
    
    When the page returns from background to foreground after the JWT
    token expires (~15 min), React Query's automatic refetch-on-focus
    triggers multiple API calls simultaneously. These all fail with 401
    Unauthorized, leaving the user with empty content.
    
    Solution:
    - Add useTokenRefreshOnFocus hook that listens to visibilitychange
    - Proactively refresh token BEFORE React Query refetches
    - Uses 2-minute buffer to catch expiring tokens early
    - Graceful error handling - logs error but doesn't block
    
    Changes:
    - Created web/src/hooks/useTokenRefreshOnFocus.ts
    - Updated isTokenExpired() to accept optional buffer parameter
    - Exported refreshAccessToken() for use by the hook
    - Integrated hook into AppInitializer (only when user authenticated)
    81ef53b3
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...