fix: stop login loop caused by unguarded folder-sync 401

The deployed app looped /login -> / -> /login forever: Login sees a
valid Supabase session and navigates to /, the global FolderProvider
pulls GET /api/v1/storage/folders, the backend rejects it with 401, and
the global error handler hard-redirects back to /login?from=/bpp.

fileSyncService's /api/v1/storage/files pull already opts out via
suppressErrorToast + skipAuthRedirect, so its 401 fails silently;
folderSyncService.list() passed neither flag, so its 401 fell through to
the redirect. Add the same flags - FolderContext.pullFromServer already
handles 4xx locally (flips serverReachable, suppresses the banner).

Note: the underlying 401 on /api/v1/storage/* with a valid session is a
backend/deployment issue (storage endpoints rejecting the Supabase
token); this change makes the frontend resilient so it degrades to
"folder sync unavailable" instead of an auth loop.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Anthony Stirling
2026-06-10 12:13:20 +01:00
co-authored by Claude Opus 4.8
parent 7f7c865888
commit 247ef6313c
@@ -62,8 +62,21 @@ function toFolderRecord(dto: ServerFolder): FolderRecord {
export const folderSyncService = { export const folderSyncService = {
async list(): Promise<FolderRecord[]> { async list(): Promise<FolderRecord[]> {
// Background sync fired automatically by the global FolderProvider on
// every (non-auth-route) load. If the backend rejects the request with a
// 401 - e.g. the storage API doesn't accept this deployment's session
// token - the error must NOT reach the global 401 handler: that handler
// hard-redirects to /login, the login page sees a valid session and
// bounces back to /, FolderProvider pulls again, and the app loops
// login->/->login forever. FolderContext.pullFromServer already handles
// 4xx locally (flips serverReachable, no banner), so fail silently here -
// mirroring fileSyncService's /api/v1/storage/files pull.
const response = await apiClient.get<ServerFolder[]>( const response = await apiClient.get<ServerFolder[]>(
"/api/v1/storage/folders", "/api/v1/storage/folders",
{
suppressErrorToast: true,
skipAuthRedirect: true,
},
); );
return (response.data ?? []).map(toFolderRecord); return (response.data ?? []).map(toFolderRecord);
}, },