Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3346986
D12685.id42099.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12685.id42099.diff
View Options
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
@@ -15,7 +15,7 @@
import { relationshipActions } from '../types/relationship-types.js';
import { syncedMetadataNames } from '../types/synced-metadata-types.js';
import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.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';
@@ -54,6 +54,8 @@
const fid = useCurrentUserFID();
+ const unlinkFID = useUnlinkFID();
+
const prevCanQueryRef = React.useRef<?boolean>();
const handleFarcasterMutuals = React.useCallback(async () => {
@@ -136,17 +138,32 @@
});
}, [loggedIn, isActive, findUserIdentities, userInfos, dispatch]);
+ const shouldCheckCurrentFIDRef = React.useRef(true);
+
const handleCurrentUserFID = React.useCallback(async () => {
if (
!loggedIn ||
!isActive ||
!findUserIdentities ||
!currentUserID ||
- fid
+ !neynarClient
) {
return;
}
+ if (fid && fid !== 'NONE' && shouldCheckCurrentFIDRef.current) {
+ const isCurrentUserFIDValid =
+ await neynarClient.checkIfCurrentUserFIDIsValid(fid);
+
+ if (isCurrentUserFIDValid) {
+ shouldCheckCurrentFIDRef.current = false;
+ return;
+ }
+
+ await unlinkFID();
+ return;
+ }
+
const currentUserIdentityObj = await findUserIdentities([currentUserID]);
const identityFID = currentUserIdentityObj[currentUserID].farcasterID;
@@ -159,7 +176,16 @@
},
});
}
- }, [loggedIn, isActive, findUserIdentities, currentUserID, fid, dispatch]);
+ }, [
+ loggedIn,
+ isActive,
+ findUserIdentities,
+ currentUserID,
+ neynarClient,
+ fid,
+ unlinkFID,
+ dispatch,
+ ]);
React.useEffect(() => {
if (!usingCommServicesAccessToken) {
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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 10:36 AM (19 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570257
Default Alt Text
D12685.id42099.diff (2 KB)
Attached To
Mode
D12685: [lib] check if the user fid is still valid
Attached
Detach File
Event Timeline
Log In to Comment