diff --git a/lib/hooks/login-hooks.js b/lib/hooks/login-hooks.js --- a/lib/hooks/login-hooks.js +++ b/lib/hooks/login-hooks.js @@ -10,7 +10,7 @@ logOutActionTypes, useIdentityLogOut, } from '../actions/user-actions.js'; -import { useKeyserverAuth } from '../keyserver-conn/keyserver-auth.js'; +import { useKeyserverAuthWithRetry } from '../keyserver-conn/keyserver-auth.js'; import { logInActionSources } from '../types/account-types.js'; import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; @@ -92,7 +92,7 @@ ], ); - const keyserverAuth = useKeyserverAuth(authoritativeKeyserverID()); + const keyserverAuth = useKeyserverAuthWithRetry(authoritativeKeyserverID()); const isRegisteredOnIdentity = useSelector( state => diff --git a/lib/keyserver-conn/keyserver-auth.js b/lib/keyserver-conn/keyserver-auth.js --- a/lib/keyserver-conn/keyserver-auth.js +++ b/lib/keyserver-conn/keyserver-auth.js @@ -175,14 +175,19 @@ type KeyserverAuthFunc = KeyserverAuthInputs => Promise; -function useKeyserverAuth(keyserverID: string): KeyserverAuthFunc { +function useKeyserverAuthWithRetry(keyserverID: string): KeyserverAuthFunc { const rawKeyserverAuth = useRawKeyserverAuth(keyserverID); const { callKeyserverEndpoint } = useCallKeyserverEndpointContext(); return React.useCallback( - (inputs: KeyserverAuthInputs) => - rawKeyserverAuth(inputs)(callKeyserverEndpoint), + async (inputs: KeyserverAuthInputs) => { + try { + return await rawKeyserverAuth(inputs)(callKeyserverEndpoint); + } catch { + return await rawKeyserverAuth(inputs)(callKeyserverEndpoint); + } + }, [rawKeyserverAuth, callKeyserverEndpoint], ); } -export { useRawKeyserverAuth, useKeyserverAuth }; +export { useRawKeyserverAuth, useKeyserverAuthWithRetry }; diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js --- a/native/account/registration/registration-server-call.js +++ b/native/account/registration/registration-server-call.js @@ -12,7 +12,7 @@ deleteAccountActionTypes, useDeleteDiscardedIdentityAccount, } from 'lib/actions/user-actions.js'; -import { useKeyserverAuth } from 'lib/keyserver-conn/keyserver-auth.js'; +import { useKeyserverAuthWithRetry } from 'lib/keyserver-conn/keyserver-auth.js'; import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js'; import { isLoggedInToKeyserver } from 'lib/selectors/user-selectors.js'; import { @@ -308,7 +308,7 @@ // STEP 2: REGISTERING ON AUTHORITATIVE KEYSERVER - const keyserverAuth = useKeyserverAuth(authoritativeKeyserverID); + const keyserverAuth = useKeyserverAuthWithRetry(authoritativeKeyserverID); const isRegisteredOnIdentity = useSelector( state =>