memos/web
Steven 81ef53b398 fix: prevent 401 errors on window focus when token expires
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)
2026-02-05 22:14:48 +08:00
..
docs refactor(react-query): optimize config, add error boundary, and remove JSDoc 2025-12-25 08:47:36 +08:00
public chore: enhance site.webmanifest in firefox (#4828) 2025-07-08 19:56:46 +08:00
src fix: prevent 401 errors on window focus when token expires 2026-02-05 22:14:48 +08:00
.gitignore chore: update gitignore 2025-04-17 23:11:36 +08:00
biome.json refactor: remove MemoContentContext and integrate MemoViewContext 2025-12-28 12:46:12 +08:00
components.json feat: themes (#4824) 2025-07-07 20:13:22 +08:00
index.html chore: prevent sensitive data caching 2025-12-20 12:33:16 +08:00
package.json fix: KaTeX math rendering with underscores (#5438) 2026-01-06 20:16:01 +08:00
pnpm-lock.yaml fix: KaTeX math rendering with underscores (#5438) 2026-01-06 20:16:01 +08:00
tsconfig.json chore: clean up unused imports and parameters across components 2025-12-27 10:18:38 +08:00
vite.config.mts refactor(web): improve MemoContent security and maintainability 2025-12-02 22:45:22 +08:00