fix: infinite reload loop on login when Telegram widget unavailable

When the Telegram OIDC widget fails to load (ad blockers, DNS, CSP),
the deep link polling fallback caused an infinite page reload:

1. pollDeepLinkToken received 202 (pending) which axios treated as success
2. loginWithDeepLink stored undefined tokens with isAuthenticated=true
3. checkAdminStatus() fired with invalid token → 401
4. Response interceptor called safeRedirectToLogin() → page reload → loop

Fixes:
- pollDeepLinkToken: validateStatus rejects non-200 (202 now caught in poll loop)
- AUTH_ENDPOINTS: add /cabinet/auth/deeplink/ and /cabinet/auth/login/auto
- safeRedirectToLogin: guard against redirect when already on /login
- loginWithDeepLink: validate response tokens before storing
- setTokens: validate tokens in store method (protects AutoLogin, VerifyEmail, etc.)
This commit is contained in:
Fringg
2026-03-20 22:28:39 +03:00
parent accde7b720
commit c34375e579
4 changed files with 21 additions and 1 deletions

View File

@@ -291,7 +291,17 @@ export const authApi = {
},
pollDeepLinkToken: async (token: string): Promise<AuthResponse> => {
const response = await apiClient.post<AuthResponse>('/cabinet/auth/deeplink/poll', { token });
// validateStatus: only treat 200 as success.
// Server returns 202 for "pending" and 410 for "expired" —
// these must reject so the polling catch-block can handle them.
// Without this, axios resolves on 202 (it's 2xx), causing
// loginWithDeepLink to set undefined tokens + isAuthenticated=true,
// which triggers checkAdminStatus() → 401 → safeRedirectToLogin() → infinite reload.
const response = await apiClient.post<AuthResponse>(
'/cabinet/auth/deeplink/poll',
{ token },
{ validateStatus: (status) => status === 200 },
);
return response.data;
},