Skip to content

useProfile

用于读取已认证用户信息的 Hook。

你可以使用此 Hook 从应用内的其他组件中读取已认证用户的个人资料信息。

tsx
import { useProfile } from '@farcaster/auth-kit';

function App() {
  const {
    isAuthenticated,
    profile: { username, fid, bio, displayName, pfpUrl },
  } = useProfile();

  return (
    <div>
      {isAuthenticated ? (
        <p>
          你好, {username}! 你的 fid 是: {fid}
        </p>
      ) : (
        <p>你尚未登录。</p>
      )}
    </div>
  );
}

返回值

ts
  {
    isAuthenticated: boolean;
    profile?: {
        fid?: number;
        username?: string;
        bio?: string;
        displayName?: string;
        pfpUrl?: string;
        custody?: Hex;
        verifications?: Hex[];
    },
  };
参数描述
isAuthenticated用户登录时为 true。
profile.fid用户的 Farcaster ID。
profile.username用户名。
profile.bio用户简介文本。
profile.displayName用户显示名称。
profile.pfpUrl用户头像 URL。
profile.custody用户 FID 托管地址。
profile.verifications用户已验证地址列表。