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 {
|
try {
|
||||||
await unsubscribe();
|
await unsubscribe();
|
||||||
await callApi('destroy');
|
await callApi('destroy');
|
||||||
@ -132,6 +132,10 @@ addActionHandler('signOut', async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getActions().reset();
|
getActions().reset();
|
||||||
|
|
||||||
|
if (payload?.forceInitApi) {
|
||||||
|
getActions().initApi();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('reset', () => {
|
addActionHandler('reset', () => {
|
||||||
|
|||||||
@ -161,7 +161,16 @@ function onUpdateConnectionState(update: ApiUpdateConnectionState) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (connectionState === 'connectionStateBroken') {
|
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 {
|
export interface ActionPayloads {
|
||||||
|
// Initial
|
||||||
|
signOut: { forceInitApi?: boolean } | undefined;
|
||||||
apiUpdate: ApiUpdate;
|
apiUpdate: ApiUpdate;
|
||||||
|
|
||||||
|
// Chats
|
||||||
openChat: {
|
openChat: {
|
||||||
id: string | undefined;
|
id: string | undefined;
|
||||||
threadId?: number;
|
threadId?: number;
|
||||||
@ -536,7 +540,7 @@ export type NonTypedActionNames = (
|
|||||||
'openSeenByModal' | 'closeSeenByModal' | 'closeReactorListModal' | 'openReactorListModal' |
|
'openSeenByModal' | 'closeSeenByModal' | 'closeReactorListModal' | 'openReactorListModal' |
|
||||||
'toggleStatistics' |
|
'toggleStatistics' |
|
||||||
// auth
|
// auth
|
||||||
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' |
|
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' |
|
||||||
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
|
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
|
||||||
// chats
|
// chats
|
||||||
'preloadTopChatMessages' | 'loadAllChats' | 'openChatWithInfo' | 'openLinkedChat' |
|
'preloadTopChatMessages' | 'loadAllChats' | 'openChatWithInfo' | 'openLinkedChat' |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user