Auth: Support aborting session right after scanning QR code

This commit is contained in:
Alexander Zinchuk 2022-03-19 21:19:46 +01:00
parent a0679c31c3
commit e7d748d379
3 changed files with 20 additions and 3 deletions

View File

@ -122,7 +122,7 @@ addActionHandler('saveSession', (global, actions, payload) => {
}
});
addActionHandler('signOut', async () => {
addActionHandler('signOut', async (_global, _actions, payload) => {
try {
await unsubscribe();
await callApi('destroy');
@ -132,6 +132,10 @@ addActionHandler('signOut', async () => {
}
getActions().reset();
if (payload?.forceInitApi) {
getActions().initApi();
}
});
addActionHandler('reset', () => {

View File

@ -161,7 +161,16 @@ function onUpdateConnectionState(update: ApiUpdateConnectionState) {
});
if (connectionState === 'connectionStateBroken') {
getActions().signOut();
// When mounting Auth `initApi` will be called from an effect. Otherwise, we force it here.
const isOnAuth = !global.authState || [
'authorizationStateWaitPhoneNumber',
'authorizationStateWaitCode',
'authorizationStateWaitPassword',
'authorizationStateWaitRegistration',
'authorizationStateWaitQrCode',
].includes(global.authState);
getActions().signOut({ forceInitApi: isOnAuth });
}
}

View File

@ -510,7 +510,11 @@ export type GlobalState = {
};
export interface ActionPayloads {
// Initial
signOut: { forceInitApi?: boolean } | undefined;
apiUpdate: ApiUpdate;
// Chats
openChat: {
id: string | undefined;
threadId?: number;
@ -536,7 +540,7 @@ export type NonTypedActionNames = (
'openSeenByModal' | 'closeSeenByModal' | 'closeReactorListModal' | 'openReactorListModal' |
'toggleStatistics' |
// auth
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' |
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' |
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
// chats
'preloadTopChatMessages' | 'loadAllChats' | 'openChatWithInfo' | 'openLinkedChat' |