Enhance Telegram authentication handling and error management

- Updated TelegramConnectionModal to handle authentication checks more robustly, allowing the QR code flow to continue even if the authentication status check fails.
- Improved error handling in checkAuthStatus to prevent failures from blocking the authentication process, ensuring a smoother user experience.
- Added logging for better visibility into authentication status and errors during the connection process.

These changes improve the reliability of the Telegram connection flow and enhance user feedback during authentication.
This commit is contained in:
Steven Enamakel
2026-01-28 05:37:43 +05:30
parent fed0f498a4
commit 39b87f25de
2 changed files with 35 additions and 9 deletions
+17 -7
View File
@@ -52,12 +52,17 @@ const TelegramConnectionModal = ({ isOpen, onClose, onComplete }: TelegramConnec
if (connectionStatus !== 'connected') {
await dispatch(connectTelegram()).unwrap();
}
// Check if already authenticated
const authCheck = await dispatch(checkAuthStatus()).unwrap();
if (authCheck) {
onComplete();
onClose();
return;
// Check if already authenticated (but don't fail if not authenticated)
try {
const authCheck = await dispatch(checkAuthStatus()).unwrap();
if (authCheck) {
onComplete();
onClose();
return;
}
} catch (err) {
// If checkAuthStatus fails, we're not authenticated - continue with QR flow
console.log('Not authenticated, proceeding with QR code flow');
}
// Start QR code flow
startQrCodeFlow();
@@ -134,7 +139,12 @@ const TelegramConnectionModal = ({ isOpen, onClose, onComplete }: TelegramConnec
// Authentication successful
setIsAuthenticating(false);
await dispatch(checkAuthStatus()).unwrap();
try {
await dispatch(checkAuthStatus()).unwrap();
} catch (err) {
// Even if checkAuthStatus fails, we know we just authenticated
console.warn('checkAuthStatus failed after authentication, but continuing:', err);
}
dispatch(setAuthStatus('authenticated'));
onComplete();
onClose();
+18 -2
View File
@@ -192,14 +192,30 @@ export const checkAuthStatus = createAsyncThunk(
async (_, { rejectWithValue }) => {
try {
const client = mtprotoService.getClient();
// First check if we're authorized without making API calls
const isAuthorized = await client.checkAuthorization();
if (isAuthorized) {
if (!isAuthorized) {
return null;
}
// Only call getMe() if we're authorized
try {
const me = await client.getMe();
return me;
} catch (error) {
// If getMe() fails, we're not actually authorized
// This can happen if the session is invalid
console.warn('getMe() failed, user not authenticated:', error);
return null;
}
return null;
} catch (error) {
// If checkAuthorization itself fails, we're definitely not authenticated
// Don't treat this as an error, just return null
if (error instanceof Error && error.message.includes('AUTH_KEY_UNREGISTERED')) {
return null;
}
return rejectWithValue(
error instanceof Error ? error.message : 'Failed to check auth status'
);