Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
feat: get user by username
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-grover committed Sep 27, 2023
1 parent d1d7021 commit b63edb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
```
Expand Down
14 changes: 14 additions & 0 deletions src/server/NeynarClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ export default class NeynarClient {
return response.result.user
}

getUserByUsername(username: string, viewer?: null): Promise<User>
getUserByUsername(
username: string,
viewer: number,
): Promise<UserWithViewerContext>
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(),
Expand Down

0 comments on commit b63edb2

Please sign in to comment.