mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-21 10:18:01 -05:00
feat: clean up UI
This commit is contained in:
@@ -22,11 +22,21 @@ export async function GET(request: Request) {
|
||||
|
||||
try {
|
||||
const neynar = new NeynarAPIClient({ apiKey });
|
||||
const { users } = await neynar.fetchUserFollowers({
|
||||
fid: parseInt(fid),
|
||||
limit: 3,
|
||||
viewerFid: parseInt(fid),
|
||||
});
|
||||
// TODO: update to use best friends endpoint once SDK merged in
|
||||
const response = await fetch(
|
||||
`https://api.neynar.com/v2/farcaster/user/best_friends?fid=${fid}&limit=3`,
|
||||
{
|
||||
headers: {
|
||||
"x-api-key": apiKey,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Neynar API error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const { users } = await response.json() as { users: { user: { fid: number; username: string } }[] };
|
||||
|
||||
const bestFriends = users.map(user => ({
|
||||
fid: user.user?.fid,
|
||||
|
||||
39
src/app/api/users/route.ts
Normal file
39
src/app/api/users/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { NeynarAPIClient } from '@neynar/nodejs-sdk';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const apiKey = process.env.NEYNAR_API_KEY;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const fids = searchParams.get('fids');
|
||||
|
||||
if (!apiKey) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Neynar API key is not configured. Please add NEYNAR_API_KEY to your environment variables.' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!fids) {
|
||||
return NextResponse.json(
|
||||
{ error: 'FIDs parameter is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const neynar = new NeynarAPIClient({ apiKey });
|
||||
const fidsArray = fids.split(',').map(fid => parseInt(fid.trim()));
|
||||
|
||||
const { users } = await neynar.fetchBulkUsers({
|
||||
fids: fidsArray,
|
||||
});
|
||||
|
||||
return NextResponse.json({ users });
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch users:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch users. Please check your Neynar API key and try again.' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user