diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js --- a/lib/utils/action-utils.js +++ b/lib/utils/action-utils.js @@ -13,6 +13,7 @@ import { getConfig } from './config.js'; import { promiseAll } from './promises.js'; import { useSelector, useDispatch } from './redux-utils.js'; +import { usingCommServicesAccessToken } from './services-utils.js'; import { ashoatKeyserverID } from './validation-utils.js'; import { serverCallStateSelector } from '../selectors/server-calls.js'; import { @@ -185,6 +186,23 @@ }); } +// This function is a shortcut that tells us whether it's worth even trying to +// call resolveKeyserverSessionInvalidation +function canResolveKeyserverSessionInvalidation() { + if (usingCommServicesAccessToken) { + // We can always resolve a keyserver session invalidation automatically + // using the Olm auth responder + return true; + } + const { resolveKeyserverSessionInvalidationUsingNativeCredentials } = + getConfig(); + // If we can't use the Olm auth responder, then we can only resolve a + // keyserver session invalidation on native, where we have access to the + // user's native credentials. Note that we can't do this for ETH users, but we + // don't know if the user is an ETH user from this function + return !!resolveKeyserverSessionInvalidationUsingNativeCredentials; +} + // This function attempts to resolve an invalid keyserver session. A session can // become invalid when a keyserver invalidates it, or due to inconsistent client // state. If the client is usingCommServicesAccessToken, then the invalidation @@ -330,15 +348,13 @@ undefined, keyserverID, ); - const { resolveKeyserverSessionInvalidationUsingNativeCredentials } = - getConfig(); + const canResolveInvalidation = canResolveKeyserverSessionInvalidation(); // This function gets called before callServerEndpoint sends a request, // to make sure that we're not in the middle of trying to recover // an invalidated cookie const waitIfCookieInvalidated = () => { - if (!resolveKeyserverSessionInvalidationUsingNativeCredentials) { - // If there is no - // resolveKeyserverSessionInvalidationUsingNativeCredentials function, + if (!canResolveInvalidation) { + // If there is no way to resolve the session invalidation, // just let the caller callServerEndpoint instance continue return Promise.resolve(null); } @@ -385,9 +401,8 @@ // its cookie, and is wondering if it should just like... give up? // Or if there's a chance at redemption const cookieInvalidationRecovery = (sessionChange: ClientSessionChange) => { - if (!resolveKeyserverSessionInvalidationUsingNativeCredentials) { - // If there is no - // resolveKeyserverSessionInvalidationUsingNativeCredentials function, + if (!canResolveInvalidation) { + // If there is no way to resolve the session invalidation, // just let the caller callServerEndpoint instance continue return Promise.resolve(null); }