Page MenuHomePhabricator

D12685.diff
No OneTemporary

D12685.diff

diff --git a/lib/components/farcaster-data-handler.react.js b/lib/components/farcaster-data-handler.react.js
--- a/lib/components/farcaster-data-handler.react.js
+++ b/lib/components/farcaster-data-handler.react.js
@@ -14,7 +14,7 @@
import { IdentityClientContext } from '../shared/identity-client-context.js';
import { relationshipActions } from '../types/relationship-types.js';
import { syncedMetadataNames } from '../types/synced-metadata-types.js';
-import { useCurrentUserFID } from '../utils/farcaster-utils.js';
+import { useCurrentUserFID, useUnlinkFID } from '../utils/farcaster-utils.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector, useDispatch } from '../utils/redux-utils.js';
import { usingCommServicesAccessToken } from '../utils/services-utils.js';
@@ -52,6 +52,8 @@
const fid = useCurrentUserFID();
+ const unlinkFID = useUnlinkFID();
+
const prevCanQueryRef = React.useRef<?boolean>();
const handleFarcasterMutuals = React.useCallback(async () => {
@@ -135,7 +137,7 @@
}, [loggedIn, isActive, findUserIdentities, userInfos, dispatch]);
const prevCanQueryHandleCurrentUserFIDRef = React.useRef<?boolean>();
- const canQueryHandleCurrentUserFID = isActive && !fid && loggedIn;
+ const canQueryHandleCurrentUserFID = isActive && loggedIn;
const handleCurrentUserFID = React.useCallback(async () => {
if (
@@ -149,11 +151,24 @@
if (
!canQueryHandleCurrentUserFID ||
!findUserIdentities ||
- !currentUserID
+ !currentUserID ||
+ !neynarClient
) {
return;
}
+ if (fid) {
+ const isCurrentUserFIDValid =
+ await neynarClient.checkIfCurrentUserFIDIsValid(fid);
+
+ if (!isCurrentUserFIDValid) {
+ await unlinkFID();
+ return;
+ }
+
+ return;
+ }
+
const currentUserIdentityObj = await findUserIdentities([currentUserID]);
const identityFID = currentUserIdentityObj[currentUserID]?.farcasterID;
@@ -170,6 +185,9 @@
canQueryHandleCurrentUserFID,
findUserIdentities,
currentUserID,
+ neynarClient,
+ fid,
+ unlinkFID,
dispatch,
]);
diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js
--- a/lib/utils/neynar-client.js
+++ b/lib/utils/neynar-client.js
@@ -308,6 +308,28 @@
throw error;
}
}
+
+ async checkIfCurrentUserFIDIsValid(fid: string): Promise<boolean> {
+ const url = getNeynarURL('2', 'user/bulk', { fids: fid });
+
+ try {
+ const response = await fetch(url, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ api_key: this.apiKey,
+ },
+ });
+
+ return response.ok;
+ } catch (error) {
+ console.log(
+ 'Failed to check if current user FID is valid:',
+ getMessageForException(error) ?? 'unknown',
+ );
+ throw error;
+ }
+ }
}
export { NeynarClient };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 5:40 AM (19 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569225
Default Alt Text
D12685.diff (2 KB)

Event Timeline