Auth: Support aborting session right after scanning QR code
This commit is contained in:
parent
a0679c31c3
commit
e7d748d379
@ -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', () => {
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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' |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user