Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3500750
D11763.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11763.diff
View Options
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
@@ -3,6 +3,7 @@
import invariant from 'invariant';
import * as React from 'react';
+import { useCallKeyserverEndpointContext } from './call-keyserver-endpoint-provider.react.js';
import { extractKeyserverIDFromID } from './keyserver-call-utils.js';
import {
CANCELLED_ERROR,
@@ -171,4 +172,16 @@
);
}
-export { useRawKeyserverAuth };
+type KeyserverAuthFunc = KeyserverAuthInputs => Promise<void>;
+
+function useKeyserverAuth(keyserverID: string): KeyserverAuthFunc {
+ const rawKeyserverAuth = useRawKeyserverAuth(keyserverID);
+ const { callKeyserverEndpoint } = useCallKeyserverEndpointContext();
+ return React.useCallback(
+ (inputs: KeyserverAuthInputs) =>
+ rawKeyserverAuth(inputs)(callKeyserverEndpoint),
+ [rawKeyserverAuth, callKeyserverEndpoint],
+ );
+}
+
+export { useRawKeyserverAuth, useKeyserverAuth };
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
@@ -10,9 +10,13 @@
useIdentityPasswordRegister,
identityRegisterActionTypes,
} from 'lib/actions/user-actions.js';
+import { useKeyserverAuth } 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 type { LogInStartingPayload } from 'lib/types/account-types.js';
+import {
+ type LogInStartingPayload,
+ logInActionSources,
+} from 'lib/types/account-types.js';
import { syncedMetadataNames } from 'lib/types/synced-metadata-types.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
@@ -58,7 +62,14 @@
type CurrentStep =
| { +step: 'inactive' }
| {
- +step: 'waiting_for_registration_call',
+ +step: 'identity_registration_dispatched',
+ +clearCachedSelections: () => void,
+ +avatarData: ?AvatarData,
+ +resolve: () => void,
+ +reject: Error => void,
+ }
+ | {
+ +step: 'authoritative_keyserver_registration_dispatched',
+clearCachedSelections: () => void,
+avatarData: ?AvatarData,
+resolve: () => void,
@@ -267,7 +278,7 @@
await commCoreModule.setSIWEBackupSecrets(siweBackupSecrets);
}
setCurrentStep({
- step: 'waiting_for_registration_call',
+ step: 'identity_registration_dispatched',
avatarData,
clearCachedSelections,
resolve,
@@ -288,7 +299,55 @@
],
);
- // STEP 2: SETTING AVATAR
+ // STEP 2: REGISTERING ON AUTHORITATIVE KEYSERVER
+
+ const keyserverAuth = useKeyserverAuth(authoritativeKeyserverID);
+
+ const isRegisteredOnIdentity = useSelector(
+ state =>
+ !!state.commServicesAccessToken &&
+ !!state.currentUserInfo &&
+ !state.currentUserInfo.anonymous,
+ );
+
+ const registeringOnAuthoritativeKeyserverRef = React.useRef(false);
+ React.useEffect(() => {
+ if (
+ !isRegisteredOnIdentity ||
+ currentStep.step !== 'identity_registration_dispatched' ||
+ registeringOnAuthoritativeKeyserverRef.current
+ ) {
+ return;
+ }
+ registeringOnAuthoritativeKeyserverRef.current = true;
+ const { avatarData, clearCachedSelections, resolve, reject } = currentStep;
+ void (async () => {
+ try {
+ await keyserverAuth({
+ authActionSource: process.env.BROWSER
+ ? logInActionSources.keyserverAuthFromWeb
+ : logInActionSources.keyserverAuthFromNative,
+ setInProgress: () => {},
+ hasBeenCancelled: () => false,
+ doNotRegister: false,
+ });
+ setCurrentStep({
+ step: 'authoritative_keyserver_registration_dispatched',
+ avatarData,
+ clearCachedSelections,
+ resolve,
+ reject,
+ });
+ } catch (e) {
+ reject(e);
+ setCurrentStep(inactiveStep);
+ } finally {
+ registeringOnAuthoritativeKeyserverRef.current = false;
+ }
+ })();
+ }, [currentStep, isRegisteredOnIdentity, keyserverAuth]);
+
+ // STEP 3: SETTING AVATAR
const uploadSelectedMedia = useUploadSelectedMedia();
const nativeSetUserAvatar = useNativeSetUserAvatar();
@@ -301,7 +360,7 @@
React.useEffect(() => {
if (
!isLoggedInToAuthoritativeKeyserver ||
- currentStep.step !== 'waiting_for_registration_call' ||
+ currentStep.step !== 'authoritative_keyserver_registration_dispatched' ||
avatarBeingSetRef.current
) {
return;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 2:43 AM (18 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2684721
Default Alt Text
D11763.diff (4 KB)
Attached To
Mode
D11763: [native] Auth with authoritative keyserver directly from registration flow
Attached
Detach File
Event Timeline
Log In to Comment