mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-11 16:49:44 +01:00
Do not destroy session on startup errors
This commit is contained in:
parent
7b035dc1f9
commit
f2e8977413
10
src/App.tsx
10
src/App.tsx
@ -3,7 +3,7 @@ import React, { withGlobal } from './lib/teact/teactn';
|
|||||||
|
|
||||||
import { GlobalActions, GlobalState } from './global/types';
|
import { GlobalActions, GlobalState } from './global/types';
|
||||||
|
|
||||||
import { INACTIVE_MARKER, PAGE_TITLE } from './config';
|
import { GRAMJS_SESSION_ID_KEY, INACTIVE_MARKER, PAGE_TITLE } from './config';
|
||||||
import { pick } from './util/iteratees';
|
import { pick } from './util/iteratees';
|
||||||
import { updateSizes } from './util/windowSize';
|
import { updateSizes } from './util/windowSize';
|
||||||
import { addActiveTabChangeListener } from './util/activeTabMonitor';
|
import { addActiveTabChangeListener } from './util/activeTabMonitor';
|
||||||
@ -15,10 +15,10 @@ import Main from './components/main/Main.async';
|
|||||||
import AppInactive from './components/main/AppInactive';
|
import AppInactive from './components/main/AppInactive';
|
||||||
// import Test from './components/test/TestNoRedundancy';
|
// import Test from './components/test/TestNoRedundancy';
|
||||||
|
|
||||||
type StateProps = Pick<GlobalState, 'authState' | 'authIsSessionRemembered'>;
|
type StateProps = Pick<GlobalState, 'authState'>;
|
||||||
type DispatchProps = Pick<GlobalActions, 'disconnect'>;
|
type DispatchProps = Pick<GlobalActions, 'disconnect'>;
|
||||||
|
|
||||||
const App: FC<StateProps & DispatchProps> = ({ authState, authIsSessionRemembered, disconnect }) => {
|
const App: FC<StateProps & DispatchProps> = ({ authState, disconnect }) => {
|
||||||
const [isInactive, markInactive] = useFlag(false);
|
const [isInactive, markInactive] = useFlag(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -53,7 +53,7 @@ const App: FC<StateProps & DispatchProps> = ({ authState, authIsSessionRemembere
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return authIsSessionRemembered ? renderMain() : <Auth />;
|
return localStorage.getItem(GRAMJS_SESSION_ID_KEY) ? renderMain() : <Auth />;
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderMain() {
|
function renderMain() {
|
||||||
@ -65,6 +65,6 @@ function renderMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default withGlobal(
|
export default withGlobal(
|
||||||
(global): StateProps => pick(global, ['authState', 'authIsSessionRemembered']),
|
(global): StateProps => pick(global, ['authState']),
|
||||||
(setGlobal, actions): DispatchProps => pick(actions, ['disconnect']),
|
(setGlobal, actions): DispatchProps => pick(actions, ['disconnect']),
|
||||||
)(App);
|
)(App);
|
||||||
|
@ -103,7 +103,6 @@ function updateCache() {
|
|||||||
'authState',
|
'authState',
|
||||||
'authPhoneNumber',
|
'authPhoneNumber',
|
||||||
'authRememberMe',
|
'authRememberMe',
|
||||||
'authIsSessionRemembered',
|
|
||||||
'authNearestCountry',
|
'authNearestCountry',
|
||||||
'currentUserId',
|
'currentUserId',
|
||||||
'contactList',
|
'contactList',
|
||||||
|
@ -71,7 +71,6 @@ export type GlobalState = {
|
|||||||
authIsLoadingQrCode?: boolean;
|
authIsLoadingQrCode?: boolean;
|
||||||
authError?: string;
|
authError?: string;
|
||||||
authRememberMe?: boolean;
|
authRememberMe?: boolean;
|
||||||
authIsSessionRemembered?: boolean;
|
|
||||||
authNearestCountry?: string;
|
authNearestCountry?: string;
|
||||||
authIsCodeViaApp?: boolean;
|
authIsCodeViaApp?: boolean;
|
||||||
authHint?: string;
|
authHint?: string;
|
||||||
|
@ -20,11 +20,6 @@ addReducer('initApi', (global: GlobalState, actions) => {
|
|||||||
const sessionId = localStorage.getItem(GRAMJS_SESSION_ID_KEY) || undefined;
|
const sessionId = localStorage.getItem(GRAMJS_SESSION_ID_KEY) || undefined;
|
||||||
|
|
||||||
void initApi(actions.apiUpdate, sessionId);
|
void initApi(actions.apiUpdate, sessionId);
|
||||||
|
|
||||||
return {
|
|
||||||
...global,
|
|
||||||
authIsSessionRemembered: Boolean(sessionId),
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
addReducer('setAuthPhoneNumber', (global, actions, payload) => {
|
addReducer('setAuthPhoneNumber', (global, actions, payload) => {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import {
|
import { DEBUG_ALERT_MSG, GLOBAL_STATE_CACHE_KEY } from '../config';
|
||||||
DEBUG_ALERT_MSG, GLOBAL_STATE_CACHE_KEY, GRAMJS_SESSION_ID_KEY,
|
|
||||||
} from '../config';
|
|
||||||
import { throttle } from './schedulers';
|
import { throttle } from './schedulers';
|
||||||
|
|
||||||
window.addEventListener('error', handleErrorEvent);
|
window.addEventListener('error', handleErrorEvent);
|
||||||
@ -29,15 +27,9 @@ export function handleError(err: Error) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For startup errors, we just clean the cache or the session and refresh the page.
|
// For startup errors, we just clean the cache and refresh the page
|
||||||
if (Date.now() - startedAt <= STARTUP_TIMEOUT) {
|
if (Date.now() - startedAt <= STARTUP_TIMEOUT && localStorage.getItem(GLOBAL_STATE_CACHE_KEY)) {
|
||||||
if (localStorage.getItem(GLOBAL_STATE_CACHE_KEY)) {
|
|
||||||
localStorage.removeItem(GLOBAL_STATE_CACHE_KEY);
|
localStorage.removeItem(GLOBAL_STATE_CACHE_KEY);
|
||||||
} else if (localStorage.getItem(GRAMJS_SESSION_ID_KEY)) {
|
|
||||||
localStorage.removeItem(GRAMJS_SESSION_ID_KEY);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isReloading = true;
|
isReloading = true;
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
Loading…
Reference in New Issue
Block a user