diff --git a/lib/keyserver-conn/recovery-utils.js b/lib/keyserver-conn/recovery-utils.js --- a/lib/keyserver-conn/recovery-utils.js +++ b/lib/keyserver-conn/recovery-utils.js @@ -18,6 +18,7 @@ import { type ClientSessionChange, genericCookieInvalidation, + type PreRequestUserState, } from '../types/session-types.js'; import callSingleKeyServerEndpoint from '../utils/call-single-keyserver-endpoint.js'; import type { @@ -165,6 +166,24 @@ const dispatch = useDispatch(); const urlPrefix = useSelector(urlPrefixSelector(keyserverID)); + const invalidateKeyserverSession = React.useCallback( + ( + source: RecoveryActionSource, + sessionChange: ClientSessionChange, + userStateBeforeRecovery: PreRequestUserState, + ) => { + setNewSession( + dispatch, + sessionChange, + userStateBeforeRecovery, + null, + source, + keyserverID, + ); + }, + [dispatch, keyserverID], + ); + return React.useCallback( async ( source: RecoveryActionSource, @@ -196,13 +215,10 @@ !sessionChange.cookie || !sessionChange.cookie.startsWith('user=') ) { - setNewSession( - dispatch, + invalidateKeyserverSession( + source, sessionChange, userStateBeforeRecovery, - null, - source, - keyserverID, ); } } catch (e) { @@ -213,18 +229,15 @@ `Error during recovery login with keyserver ${keyserverID}`, e, ); - setNewSession( - dispatch, + invalidateKeyserverSession( + source, genericCookieInvalidation, userStateBeforeRecovery, - null, - source, - keyserverID, ); throw e; } }, - [keyserverID, dispatch, cookie, urlPrefix], + [keyserverID, dispatch, cookie, urlPrefix, invalidateKeyserverSession], ); }