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');
|
||||
}
|
||||
|
||||
await client.start({
|
||||
phoneNumber: onRequestPhoneNumber,
|
||||
phoneCode: onRequestCode,
|
||||
password: onRequestPassword,
|
||||
firstAndLastNames: onRequestRegistration,
|
||||
qrCode: onRequestQrCode,
|
||||
onError: onAuthError,
|
||||
initialMethod: 'qrCode',
|
||||
});
|
||||
try {
|
||||
await client.start({
|
||||
phoneNumber: onRequestPhoneNumber,
|
||||
phoneCode: onRequestCode,
|
||||
password: onRequestPassword,
|
||||
firstAndLastNames: onRequestRegistration,
|
||||
qrCode: onRequestQrCode,
|
||||
onError: onAuthError,
|
||||
initialMethod: 'qrCode',
|
||||
});
|
||||
} catch (err) {
|
||||
onUpdate({
|
||||
'@type': 'updateConnectionState',
|
||||
connectionState: 'connectionStateBroken',
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
||||
@ -244,7 +244,12 @@ class TelegramClient {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async destroy() {
|
||||
await this.disconnect();
|
||||
try {
|
||||
await this.disconnect();
|
||||
} catch (err) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
this.session.delete();
|
||||
this._eventBuilders = [];
|
||||
}
|
||||
|
||||
@ -126,8 +126,12 @@ addReducer('saveSession', (global, actions, payload) => {
|
||||
|
||||
addReducer('signOut', () => {
|
||||
(async () => {
|
||||
await unsubscribe();
|
||||
await callApi('destroy');
|
||||
try {
|
||||
await unsubscribe();
|
||||
await callApi('destroy');
|
||||
} catch (err) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
getDispatch().reset();
|
||||
})();
|
||||
|
||||
@ -150,13 +150,13 @@ function onUpdateConnectionState(update: ApiUpdateConnectionState) {
|
||||
}
|
||||
|
||||
function onUpdateSession(update: ApiUpdateSession) {
|
||||
const { sessionData } = update;
|
||||
const { authRememberMe, authState } = getGlobal();
|
||||
if (!authRememberMe || authState !== 'authorizationStateReady') {
|
||||
|
||||
if (!authRememberMe || (sessionData && authState !== 'authorizationStateReady')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { sessionData } = update;
|
||||
|
||||
getDispatch().saveSession({ sessionData });
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user