diff --git a/README.md b/README.md index 029bbae..a87e5cf 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Create Farcaster apps with Neynar. Built with Next.js in mind, but works with an This repo is a work in progress, use at your own risk! Currently, the following features are supported: - [x] Sign in -- [x] Get user profile by FID +- [x] Get user profile by FID or username - [x] Fetch feed by following/channel/FID list - [x] Post casts - [x] Cast reactions (like/unlike/recast/unrecast) @@ -245,6 +245,8 @@ export async function GET(request: Request, { params }: Props) { // const viewer = searchParams.get('viewer') const user = await neynarClient.getUserByFid(fid /*, viewer */) + // Or fetch by username + // await neynarClient.getUserByUsername('alexgrover.eth' /*, viewer */) return NextResponse.json(signer) } ``` diff --git a/src/server/NeynarClient.ts b/src/server/NeynarClient.ts index b66581b..a0106f1 100644 --- a/src/server/NeynarClient.ts +++ b/src/server/NeynarClient.ts @@ -67,6 +67,20 @@ export default class NeynarClient { return response.result.user } + getUserByUsername(username: string, viewer?: null): Promise + getUserByUsername( + username: string, + viewer: number, + ): Promise + async getUserByUsername(username: string, viewer?: number | null) { + const params = new URLSearchParams({ username }) + if (viewer) params.set('viewerFid', viewer.toString()) + const response = await this.get<{ + result: { user: User | UserWithViewerContext } + }>('user-by-username', params, 1) + return response.result.user + } + getFollowingFeed(fid: number, { cursor, limit }: Pagination = {}) { const params = new URLSearchParams({ fid: fid.toString(),