diff --git a/src/app/api/user/[id]/followers/route.ts b/src/app/api/user/[id]/followers/route.ts new file mode 100644 index 0000000..0e80fb3 --- /dev/null +++ b/src/app/api/user/[id]/followers/route.ts @@ -0,0 +1,29 @@ +import { LimitType } from "@lens-protocol/client"; +import { NextRequest, NextResponse } from "next/server"; +import { getServerAuth } from "~/utils/getServerAuth"; + +export const dynamic = "force-dynamic"; + +export async function GET(req: NextRequest, { params }: { params: { id: string } }) { + const id = params.id; + const cursor = req.nextUrl.searchParams.get("cursor") ?? undefined; + + try { + const { client } = await getServerAuth(); + + const following = await client.profile.followers({ + limit: LimitType.Fifty, + of: id, + cursor + }); + + if (!following) { + return NextResponse.json({ error: "Failed to fetch followers" }, { status: 500 }); + } + + return NextResponse.json({ users: following, nextCursor: following.pageInfo.next }, { status: 200 }); + } catch (error) { + console.error("Failed to follow profile: ", error.message); + return NextResponse.json({ error: `${error.message}` }, { status: 500 }); + } +} diff --git a/src/app/api/user/[id]/following/route.ts b/src/app/api/user/[id]/following/route.ts index cccb484..5ac61b9 100644 --- a/src/app/api/user/[id]/following/route.ts +++ b/src/app/api/user/[id]/following/route.ts @@ -1,25 +1,27 @@ -import { NextResponse } from "next/server"; +import { LimitType } from "@lens-protocol/client"; +import { NextRequest, NextResponse } from "next/server"; import { getServerAuth } from "~/utils/getServerAuth"; export const dynamic = "force-dynamic"; -export async function GET({ params }: { params: { id: string } }) { +export async function GET(req: NextRequest, { params }: { params: { id: string } }) { const id = params.id; + const cursor = req.nextUrl.searchParams.get("cursor") ?? undefined; try { - const { client, profileId: authedProfileId } = await getServerAuth(); + const { client } = await getServerAuth(); - const followers = await client.profile.following({ + const following = await client.profile.following({ + cursor, for: id, + limit: LimitType.Fifty, }); - if (!followers) { + if (!following) { return NextResponse.json({ error: "Failed to fetch followers" }, { status: 500 }); } - const isFollowingMe = followers.items.some((follower) => follower.id === authedProfileId); - - return NextResponse.json({ result: isFollowingMe }, { status: 200 }); + return NextResponse.json({ users: following }, { status: 200 }); } catch (error) { console.error("Failed to follow profile: ", error.message); return NextResponse.json({ error: `${error.message}` }, { status: 500 });