More fixes for broken sessions
This commit is contained in:
parent
1264f0d24a
commit
15e4cc25c0
@ -70,15 +70,24 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
|||||||
console.log('[GramJs/client] CONNECTING');
|
console.log('[GramJs/client] CONNECTING');
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.start({
|
try {
|
||||||
phoneNumber: onRequestPhoneNumber,
|
await client.start({
|
||||||
phoneCode: onRequestCode,
|
phoneNumber: onRequestPhoneNumber,
|
||||||
password: onRequestPassword,
|
phoneCode: onRequestCode,
|
||||||
firstAndLastNames: onRequestRegistration,
|
password: onRequestPassword,
|
||||||
qrCode: onRequestQrCode,
|
firstAndLastNames: onRequestRegistration,
|
||||||
onError: onAuthError,
|
qrCode: onRequestQrCode,
|
||||||
initialMethod: 'qrCode',
|
onError: onAuthError,
|
||||||
});
|
initialMethod: 'qrCode',
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
onUpdate({
|
||||||
|
'@type': 'updateConnectionState',
|
||||||
|
connectionState: 'connectionStateBroken',
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|||||||
@ -244,7 +244,12 @@ class TelegramClient {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async destroy() {
|
async destroy() {
|
||||||
await this.disconnect();
|
try {
|
||||||
|
await this.disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
this.session.delete();
|
this.session.delete();
|
||||||
this._eventBuilders = [];
|
this._eventBuilders = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,8 +126,12 @@ addReducer('saveSession', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('signOut', () => {
|
addReducer('signOut', () => {
|
||||||
(async () => {
|
(async () => {
|
||||||
await unsubscribe();
|
try {
|
||||||
await callApi('destroy');
|
await unsubscribe();
|
||||||
|
await callApi('destroy');
|
||||||
|
} catch (err) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
getDispatch().reset();
|
getDispatch().reset();
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -150,13 +150,13 @@ function onUpdateConnectionState(update: ApiUpdateConnectionState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onUpdateSession(update: ApiUpdateSession) {
|
function onUpdateSession(update: ApiUpdateSession) {
|
||||||
|
const { sessionData } = update;
|
||||||
const { authRememberMe, authState } = getGlobal();
|
const { authRememberMe, authState } = getGlobal();
|
||||||
if (!authRememberMe || authState !== 'authorizationStateReady') {
|
|
||||||
|
if (!authRememberMe || (sessionData && authState !== 'authorizationStateReady')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sessionData } = update;
|
|
||||||
|
|
||||||
getDispatch().saveSession({ sessionData });
|
getDispatch().saveSession({ sessionData });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user