mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-02 09:37:47 +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 { INACTIVE_MARKER, PAGE_TITLE } from './config';
|
||||
import { GRAMJS_SESSION_ID_KEY, INACTIVE_MARKER, PAGE_TITLE } from './config';
|
||||
import { pick } from './util/iteratees';
|
||||
import { updateSizes } from './util/windowSize';
|
||||
import { addActiveTabChangeListener } from './util/activeTabMonitor';
|
||||
@ -15,10 +15,10 @@ import Main from './components/main/Main.async';
|
||||
import AppInactive from './components/main/AppInactive';
|
||||
// import Test from './components/test/TestNoRedundancy';
|
||||
|
||||
type StateProps = Pick<GlobalState, 'authState' | 'authIsSessionRemembered'>;
|
||||
type StateProps = Pick<GlobalState, 'authState'>;
|
||||
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);
|
||||
|
||||
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() {
|
||||
@ -65,6 +65,6 @@ function renderMain() {
|
||||
}
|
||||
|
||||
export default withGlobal(
|
||||
(global): StateProps => pick(global, ['authState', 'authIsSessionRemembered']),
|
||||
(global): StateProps => pick(global, ['authState']),
|
||||
(setGlobal, actions): DispatchProps => pick(actions, ['disconnect']),
|
||||
)(App);
|
||||
|
@ -103,7 +103,6 @@ function updateCache() {
|
||||
'authState',
|
||||
'authPhoneNumber',
|
||||
'authRememberMe',
|
||||
'authIsSessionRemembered',
|
||||
'authNearestCountry',
|
||||
'currentUserId',
|
||||
'contactList',
|
||||
|
@ -71,7 +71,6 @@ export type GlobalState = {
|
||||
authIsLoadingQrCode?: boolean;
|
||||
authError?: string;
|
||||
authRememberMe?: boolean;
|
||||
authIsSessionRemembered?: boolean;
|
||||
authNearestCountry?: string;
|
||||
authIsCodeViaApp?: boolean;
|
||||
authHint?: string;
|
||||
|
@ -20,11 +20,6 @@ addReducer('initApi', (global: GlobalState, actions) => {
|
||||
const sessionId = localStorage.getItem(GRAMJS_SESSION_ID_KEY) || undefined;
|
||||
|
||||
void initApi(actions.apiUpdate, sessionId);
|
||||
|
||||
return {
|
||||
...global,
|
||||
authIsSessionRemembered: Boolean(sessionId),
|
||||
};
|
||||
});
|
||||
|
||||
addReducer('setAuthPhoneNumber', (global, actions, payload) => {
|
||||
|
@ -1,6 +1,4 @@
|
||||
import {
|
||||
DEBUG_ALERT_MSG, GLOBAL_STATE_CACHE_KEY, GRAMJS_SESSION_ID_KEY,
|
||||
} from '../config';
|
||||
import { DEBUG_ALERT_MSG, GLOBAL_STATE_CACHE_KEY } from '../config';
|
||||
import { throttle } from './schedulers';
|
||||
|
||||
window.addEventListener('error', handleErrorEvent);
|
||||
@ -29,15 +27,9 @@ export function handleError(err: Error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For startup errors, we just clean the cache or the session and refresh the page.
|
||||
if (Date.now() - startedAt <= STARTUP_TIMEOUT) {
|
||||
if (localStorage.getItem(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;
|
||||
}
|
||||
// For startup errors, we just clean the cache and refresh the page
|
||||
if (Date.now() - startedAt <= STARTUP_TIMEOUT && localStorage.getItem(GLOBAL_STATE_CACHE_KEY)) {
|
||||
localStorage.removeItem(GLOBAL_STATE_CACHE_KEY);
|
||||
|
||||
isReloading = true;
|
||||
window.location.reload();
|
||||
|
Loading…
Reference in New Issue
Block a user