I am currently facing an issue with the Amity SDK in my Next.js application, and I’d appreciate your help in resolving it.
I am using the TypeScript SDK of Amity and encountering the following error: “Error: Amity SDK (800000): Connect client first.” The error is raised when I try to retrieve follow information using the UserRepository.Relationship.getFollowInfo
function.
Code Snippet: Here is a simplified version of the relevant code:
const sessionHandler: Amity.SessionHandler = {
sessionWillRenewAccessToken(renewal) {
renewal.renew();
},
};
const handleConnect = async (userId: string, displayName: string) => {
console.log(userId, displayName);
return Client.login({ userId, displayName }, sessionHandler)
.then(() => {
console.log('handleConnect completed');
});
};
useEffect(() => {
if (user) {
handleConnect(`${user?.email}`, `${user?.name}`);
console.log("handleConnect completed");
}
}, [user]);
const [followInfo, setFollowInfo] = useState<Amity.FollowInfo>();
useEffect(() => {
disposers.push(
UserRepository.Relationship.getFollowInfo(id as string, ({ data: followInfo, loading, error }) => {
disposers.push(subscribeTopic(getMyFollowersTopic()));
disposers.push(subscribeTopic(getMyFollowingsTopic()));
setFollowInfo(followInfo);
}),
);
console.log(followInfo);
return () => disposers.forEach(fn => fn());
}, [id]);